Can help me to solve the calculation for the average part.
Numbers in the text file is 10, 20, 30,40, 50. Average is30.
My output answer is wrong.
1 #include 2 #include HN3&ST89 4 int main() { 5 6 7 10 11 12 13 14 15 16 17 18 19 20 21 22} char number [5]; int i, count=0, total=0; double num=5; FILE *file; file = fopen("textFile.txt", "r"); if (file) { } while ((number = fgetc(file)) != EOF) { printf("%c", number); total += num; count++; } printf("Average = %.2f\n", total/num); fclose(file); return 0;
10 20 30 40 50 Average = 15.00
Can help me to solve the calculation for the average part. Numbers in the text file is 10, 20, 30,40, 50. Average is 30.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am