Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Найти два максимума в получаемом массиве (возможно, совпадающих)
- #include <stdio.h>
- #define CORRECT_ENDING 0
- #define LACK_OF_ELEMENTS -1
- int process(FILE *f, int *first_max, int *second_max)
- {
- int num;
- int temp;
- int rc;
- if (fscanf(f, "%d", first_max))
- {
- if (fscanf(f, "%d", second_max))
- {
- if (first_max < second_max)
- {
- temp = *first_max;
- *first_max = *second_max;
- *second_max = temp;
- }
- while (fscanf(f, "%d", &num))
- {
- if (num >= *first_max)
- {
- *second_max = *first_max;
- *first_max = num;
- }
- else if (num > *second_max)
- {
- *second_max = num;
- }
- }
- rc = CORRECT_ENDING;
- }
- else rc = LACK_OF_ELEMENTS;
- }
- else rc = LACK_OF_ELEMENTS;
- if (rc == CORRECT_ENDING)
- return CORRECT_ENDING;
- else
- return LACK_OF_ELEMENTS;
- }
- int main()
- {
- int first_max, second_max;
- int rc;
- if ((rc = process(stdin, &first_max, &second_max)) == CORRECT_ENDING)
- printf("%d %d", first_max, second_max);
- else
- {
- printf("There are not enough data.\n");
- }
- return rc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement