Advertisement
imedvedev

Mazaev File

Dec 21st, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <ctype.h>
  5.  
  6. int main() {
  7.     FILE* myfile;
  8.    
  9.     myfile = fopen("/Users/imedvedev/Documents/programming/xcode/lab6/lab7890/lab7890/f.txt", "r");
  10.     if ( myfile == NULL ) {
  11.         printf("Cannot open TEXT file\n");
  12.         return 1;
  13.     }
  14.    
  15.     int a, max = 0, min = 0;
  16.     while (fscanf(myfile, "%d", &a) == 1) {
  17.         if(a > max) {
  18.             max = a;
  19.         }
  20.     }
  21.    
  22.     fseek(myfile, 0, SEEK_SET);
  23.     while (fscanf(myfile, "%d", &a) == 1) {
  24.         if(min == 0) {
  25.             if(a < max) {
  26.                 min = a;
  27.             }
  28.         } else {
  29.             if(a < min) {
  30.                 min = a;
  31.             }
  32.         }
  33.     }
  34.    
  35.     printf("MAX: %d \nMIN: %d\nСумма: %d\n", max, min, max+min);
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement