Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <ctype.h>
- int main() {
- FILE* myfile;
- myfile = fopen("/Users/imedvedev/Documents/programming/xcode/lab6/lab7890/lab7890/f.txt", "r");
- if ( myfile == NULL ) {
- printf("Cannot open TEXT file\n");
- return 1;
- }
- int a, max = 0, min = 0;
- while (fscanf(myfile, "%d", &a) == 1) {
- if(a > max) {
- max = a;
- }
- }
- fseek(myfile, 0, SEEK_SET);
- while (fscanf(myfile, "%d", &a) == 1) {
- if(min == 0) {
- if(a < max) {
- min = a;
- }
- } else {
- if(a < min) {
- min = a;
- }
- }
- }
- printf("MAX: %d \nMIN: %d\nСумма: %d\n", max, min, max+min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement