Write in C program Write a C program, grade. c, which includes a function, calcu
ID: 3731182 • Letter: W
Question
Write in C program
Write a C program, grade. c, which includes a function, calculateAverage(), that can calculate the average of an arbitrary number of test scores. Your program will not know in advance how many test scores will be entered into your function so you will need to use a sentinel value (-1) to erminate the while loop used to collect the test scores. The test scores are integers in the range 0 to 100 and the test score average should be output to two decimal places. Be sure that the user prompts and grades input into the program are displayed in the output file. Provided below is the main() function that I would like you to use for your program int main (void) int i; fp fopen ("csis.txt", " calculat eAverage () ; c.mam fclose(fp ; return 0 Please do not modify the main() function. It should appear as the first function in the program. Be sure to use function prototypes for each of the functions that are used in your program. Note that the for loop invokes the calculateAverage () function four times Each time the calculateAverage() function is invoked, a different set of test grades will be entered. Please be sure to use the data shown below: First: 78, 93, 45, 88, 89, 1 | Second : 87, 68, 100, -1 Third: 84, 86, 90, 86, 96, 68, 82, 1 Fourth: -1Explanation / Answer
float calculateAverage(int* arr, int size)
{
float result = 0;
int i;
for (i = 0; i < size; i++) {
result += *(arr + i);
}
result = result / size;
return result;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.