Please do this in C:
Write a program that takes the name of the file that you created as input, find the maximum and minimum among all the numbers in the file, and output them.
#include <stdio.h> int main() { char filename[100]; int num, min = 0, max = 0, count = 0; printf("Enter file name: "); scanf("%s", filename); FILE *fp = fopen(filename, "r"); if (fp) { while (fscanf(fp, "%d", &num) != EOF) { if (count == 0) { max = num; min = num; } if (num > max) { max = num; } if (num < min) { min = num; } ++count; } printf("Maximum value in %s is %d\n", filename, max); printf("Minimum value in %s is %d\n", filename, min); fclose(fp); } else { printf("%s does not exists\n", filename); } return 0; }
Get Answers For Free
Most questions answered within 1 hours.