Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program which reads 20 integers from a file and stores them in an arra

ID: 3764210 • Letter: W

Question

Write a C program which reads 20 integers from a file and stores them in an array. The array is then analyzed to compute the average of all the values in the array and finally all of the values that are above the average should be printed out to the screen. Specifically, you must write two functions: main() and print_above_average().

main() reads 20 integers from a file named "numbers.txt" and stores them in an array.

Then, print_above_average() should be called to read through the array, compute the average, and then print out all values in the array that are above the average.In particular, for each value above the average it should print the index in the array and the value itself.print_above_average() should take two arguments: the array and the number of values in the array.

plz could anyone who is really good in C programming help me out with this question? thank u in advance .

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

void print_above_average(int arr[], int len) {

double avg, sum=0;

int i;

for (i=0; i<len; i++) {

sum+=arr[i];

}

avg=sum/len;

  

printf("Values above average are: ");

for (i=0; i<len; i++) {

if (arr[i] > avg) {

printf("%d ", arr[i]);

}

}

}

int main() {

FILE *fp;

fp = fopen("numbers.txt", "r");

int arr[20], i;

int len=20;

  

for (i=0; i<len; i++) {

fscanf(fp, "%d", &arr[i]);

}

  

print_above_average(arr, len);

  

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote