Advertisement
Bisus

Untitled

Oct 3rd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1.   //Программа определяет количество чисел, равных минимальному из всей целой последовательноости
  2.  
  3. #include<stdio.h>
  4. /*int array(FILE *inp1, int *err);
  5. int number(int numbers[], int i);
  6.  
  7. int number(int numbers[], int i)
  8. {
  9.     int max_elem, max = 1, j, t, cnt=0;
  10.     for (j = 0; j < i; ++j)
  11.     {
  12.         if (numbers[j+1] < numbers[j])
  13.         {
  14.             cnt=0;
  15.        
  16.             numbers [j] = = numbers [j+1];
  17.         } else cnt++;
  18.     }
  19.  
  20.     return cnt;
  21. }*/
  22.  
  23.  
  24. int array(FILE *inp1, int *a/* Массив, его заполняем */, int n/* Длина массива */)//Функция, проверяющая наличие данных в файле и заполняющая массив
  25. {
  26.     int x1, i = 0;
  27.     //int numbers[1000];
  28.  
  29.     if (fscanf(inp1, "%d", &x1) <= 0 || x1 == 0)//Проверяем наличие чисел
  30.     {
  31.         return 1;// Возвращаем код ошибки
  32.     }
  33.  
  34.     while (fscanf(inp1, "%d", &a[i]) >= 0)//пока возможно считываем числа из файла и заполняем массив
  35.         ++i;
  36.  
  37.     return 0;
  38. }
  39.  
  40. int main(void)
  41. {
  42.     int result, code_err;//code_err принимает значение 1 при наличии ошибки
  43.     FILE *input1;
  44.     char filename[60];
  45.     int n = 1000;
  46.     int a[1000];
  47.  
  48.     printf("Write file name, please");
  49.     scanf("%s", filename);
  50.     input1 = fopen(filename, "r");
  51.     if (input1 == NULL)//искомый файл не найден
  52.     {
  53.         printf ("No such file: %s", filename);
  54.  
  55.         return 0;//останавливаем программу
  56.     }
  57.  
  58.     code_err = array(input1, a, n);
  59.  
  60.     if (code_err == 1)//При отсутствии чисел в файле выводит сообщение об этом
  61.     {
  62.         printf("No numbers in file");
  63.  
  64.         return 0;//останавливаем программу
  65.     }
  66.  
  67.     //printf("The most common element is %d", result);//Выводим количество различных чисел в последовательности
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement