I’m having problem counting the value for my array.
The program should work this way
>open file text data (thousands of data containing integer and float)
>for every 1-15 data (either integer or float)
>read the 4th data value
>compare the 4th data with the threshold value
>if 4th data is less than threshold value
>count, add 1 to sum
>endloop
>print the data sum that is lesser than threshold valueThanks in advace!Code:#include <stdio.h> int main(void) { int i,sum; float avg=5.828; float f[15]; FILE *data; data = fopen("avg_data.txt","r"); while(feof(data)==0) { for( i=0; i<15; i++ ) { fscanf(data," %f",&f[i]); } printf("%.2f\n",f[3]); } if(f[3]< avg) sum++; printf("Number of data that is below average is %d\n",sum); return 0; }![]()



LinkBack URL
About LinkBacks



