x2311

Untitled

Jun 7th, 2022
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define INPUT "..\\tess.txt"
  6. #define OUTPUT "output.txt"
  7. #define N 5
  8.  
  9.  
  10. /**
  11.  * реалізував числа Фібоначчі. якщо сума попередніх 2 == число то вилучають його
  12.  * Перші 2 числа вилучаємо
  13.  *
  14.  * Маємо -> 1 2 3 12 4 16
  15.  * вилучаємо 1 и 2. Третій елемент 3 то вилучаємо так як перший + другий елемент == 3
  16.  *                  Шостий величаемо так як 12+ 4 ==16
  17.  *          Відповідь маємо ряд: 12 4
  18.  * @return 0
  19.  */
  20.  
  21. int fileIsOpen(FILE *file, char fileName[]) {
  22.     if (file == NULL) {
  23.         printf("%s is not open", fileName);
  24.         return -1;
  25.     }
  26. }
  27.  
  28. int main() {
  29.     int size = N;
  30.  
  31.     FILE *myFile;
  32.     myFile = fopen(INPUT, "r");
  33.     //if(fileIsOpen(myFile, INPUT) == -1) return -1;
  34.     //read file into array
  35.     int inputArray[size];
  36.  
  37.     for (int i = 0; i < size; i++) {
  38.         fscanf(myFile, "%d", &inputArray[i]);
  39.     }
  40.  
  41.     FILE *o = fopen(OUTPUT, "w");
  42.     //if(fileIsOpen(myFile, INPUT) == -1) return -2;
  43.  
  44.     printf("\n");
  45.     for (int i = 0, t = 0; i < sizeof(inputArray) / sizeof(inputArray[0]); ++i, t = 0) {
  46.         if (i > 2 && inputArray[i - 2] + inputArray[i - 2] != inputArray[i]) {
  47.             fprintf(o, "%d ", inputArray[i]);
  48.         }
  49.     }
  50.     fclose(o);
  51. }
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment