-
Notifications
You must be signed in to change notification settings - Fork 0
/
Activity: find the end of the file
41 lines (33 loc) · 1.85 KB
/
Activity: find the end of the file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* You are still teaching a class on C-programming! You would like to find out whether the students in your class did better on the most recent assignment than the students in your colleagues' classes. The average grades of all these classes are stored in a file called "gradeComparison.txt". The first number stored in the file represents the average grade of the students in your class. All of the subsequent numbers represent the average grades of students from other sections. For example, if the file contained the following:
95.23 94.80 91.56
this would mean that the students in your class received an average grade of 95.23 on the last assignment, which is higher than the average grades received by students in the other sections.
If, on the other hand, the file was
95.23 94.80 91.56 96.40 93.25
then this would mean that the students in the fourth class received a slightly higher grade than the students in your class.
Your job is to find out whether the students in your class did better than the students in the other classes and if so, print out the word "Yes". If on the other hand students in another class did better than your students then you should print out "No", followed by one space, followed by the number of the first class in the file that had a better grade average.*/
#include <stdio.h>
int main(void){
FILE *ifile;
int N=0, M=0, reg=0;
double avgrade, avclass, bestave;
ifile=fopen("gradeComparison.txt","r");
fscanf(ifile,"%lf",&avgrade);
M=1;
avclass=avgrade;
bestave=0;
while(fscanf(ifile,"%lf",&avgrade)!=EOF){
M++;
if(avclass>avgrade){
N++;
}else if(avgrade>bestave && reg ==0){
bestave=avgrade;
reg=M;
}else{
}
}
if(N==M && reg==0){
printf("Yes");
}else{
printf("No %d",reg);
}
}