Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Программа определяет количество чисел, равных минимальному из всей целой последовательноости
- #include<stdio.h>
- /*int array(FILE *inp1, int *err);
- int number(int numbers[], int i);
- int number(int numbers[], int i)
- {
- int max_elem, max = 1, j, t, cnt=0;
- for (j = 0; j < i; ++j)
- {
- if (numbers[j+1] < numbers[j])
- {
- cnt=0;
- numbers [j] = = numbers [j+1];
- } else cnt++;
- }
- return cnt;
- }*/
- int array(FILE *inp1, int *a/* Массив, его заполняем */, int n/* Длина массива */)//Функция, проверяющая наличие данных в файле и заполняющая массив
- {
- int x1, i = 0;
- //int numbers[1000];
- if (fscanf(inp1, "%d", &x1) <= 0 || x1 == 0)//Проверяем наличие чисел
- {
- return 1;// Возвращаем код ошибки
- }
- while (fscanf(inp1, "%d", &a[i]) >= 0)//пока возможно считываем числа из файла и заполняем массив
- ++i;
- return 0;
- }
- int main(void)
- {
- int result, code_err;//code_err принимает значение 1 при наличии ошибки
- FILE *input1;
- char filename[60];
- int n = 1000;
- int a[1000];
- printf("Write file name, please");
- scanf("%s", filename);
- input1 = fopen(filename, "r");
- if (input1 == NULL)//искомый файл не найден
- {
- printf ("No such file: %s", filename);
- return 0;//останавливаем программу
- }
- code_err = array(input1, a, n);
- if (code_err == 1)//При отсутствии чисел в файле выводит сообщение об этом
- {
- printf("No numbers in file");
- return 0;//останавливаем программу
- }
- //printf("The most common element is %d", result);//Выводим количество различных чисел в последовательности
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement