Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <cmath>
  3.  
  4. // Формат файла Zadan1.txt:
  5. // 0 0
  6. // 1 1
  7. // и т.д.
  8.  
  9. int main()
  10. {
  11.     FILE *file;
  12.  
  13.     fopen_s(&file, "Zadan1.txt", "r");
  14.  
  15.     if (!file) {
  16.         printf("%s", "Не удалось открыть файл");
  17.         return -1;
  18.     }
  19.  
  20.     char buff[100];
  21.  
  22.     int i = 0;
  23.     float x, y;
  24.     float points[2][10];
  25.  
  26.     while (fgets(buff, 100, file)) {
  27.         sscanf_s(buff, "%f %f", &x, &y);
  28.  
  29.         printf("%.1f %.1f\n", x, y);
  30.  
  31.         points[0][i] = x;
  32.         points[1][i] = y;
  33.  
  34.         i++;
  35.     }
  36.  
  37.     fclose(file);
  38.  
  39.     fopen_s(&file, "Otvet1.txt", "w");
  40.  
  41.     if (!file) {
  42.         printf("%s", "Не удалось создать или открыть файл");
  43.         return -1;
  44.     }
  45.  
  46.     int n = -1;
  47.  
  48.     for (int j = 0; j < 10; j++) {
  49.         x = points[0][j];
  50.         y = points[1][j];
  51.  
  52.         if (pow(x, 2) + pow(y, 2) >= pow(2, 2)) {
  53.             n = 0;
  54.         }
  55.         else {
  56.             if (y > 1) {
  57.                 n = 2;
  58.             }
  59.             else {
  60.                 n = 1;
  61.             }
  62.         }
  63.  
  64.         fprintf(file, "Точка №%i: (%.1f, %.1f) принадлежит зоне %i\n", j + 1, x, y, n);
  65.     }
  66.  
  67.     fclose(file);
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement