avatar
Untitled

Guest 887 19th May, 2023

#include <stdio.h>
#include <math.h>

#define RADIUS 5

int main() {
    FILE *file;
    char filename[100];
    int n, i;
    int x, y;
    int outside_count = 0;
    int inside_count = 0;

    printf("Nhap ten tap tin: ");
    scanf("%s", filename);

    file = fopen(filename, "r");
    if (file == NULL) {
        printf("Loi mo tap tin.\n");
        return 1;
    }

    // Đọc số điểm
    fscanf(file, "%d", &n);

    // Đọc tọa độ và kiểm tra điểm nằm trong hoặc ngoài đường tròn
    for (i = 0; i < n; i++) {
        fscanf(file, "%d %d", &x, &y);

        // Tính khoảng cách từ điểm đến tâm O
        double distance = sqrt(x * x + y * y);

        if (distance > RADIUS) {
            outside_count++;
        } else {
            inside_count++;
        }
    }

    fclose(file);

    printf("So diem nam ben ngoai: %d\n", outside_count);
    printf("So diem nam trong duong tron tam O, ban kinh 5: %d\n", inside_count);

    return 0;
}
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data