Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <cmath>
- // Формат файла Zadan1.txt:
- // 0 0
- // 1 1
- // и т.д.
- int main()
- {
- FILE *file;
- fopen_s(&file, "Zadan1.txt", "r");
- if (!file) {
- printf("%s", "Не удалось открыть файл");
- return -1;
- }
- char buff[100];
- int i = 0;
- float x, y;
- float points[2][10];
- while (fgets(buff, 100, file)) {
- sscanf_s(buff, "%f %f", &x, &y);
- printf("%.1f %.1f\n", x, y);
- points[0][i] = x;
- points[1][i] = y;
- i++;
- }
- fclose(file);
- fopen_s(&file, "Otvet1.txt", "w");
- if (!file) {
- printf("%s", "Не удалось создать или открыть файл");
- return -1;
- }
- int n = -1;
- for (int j = 0; j < 10; j++) {
- x = points[0][j];
- y = points[1][j];
- if (pow(x, 2) + pow(y, 2) >= pow(2, 2)) {
- n = 0;
- }
- else {
- if (y > 1) {
- n = 2;
- }
- else {
- n = 1;
- }
- }
- fprintf(file, "Точка №%i: (%.1f, %.1f) принадлежит зоне %i\n", j + 1, x, y, n);
- }
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement