The program given below is a very simple program without any compression. No separate function is written for calculating the average. This program serves the solve purpose of calculating the scores.
This program does the following:
1. Get the number of scores
2. Get the scores
3. Calculate the total of scores
4. Calculate the average and print it.
#define MAX 50
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int num;
int i;
int scores[MAX];
int total;
float average;
/*Get the number of scores*/
fprintf(stdout, "Please enter the number of scores below => ");
fscanf(stdin, "%d", &num);
/*Get the scores*/
fprintf(stdout, "Please enter the scores below => \n");
for(i=0; i<num; i++)
{
fscanf(stdin, "%d", &scores[i]);
}
/*Calculate the summation of all the scores*/
for(i=0; i<num; i++)
{
total = total + scores[i];
}
/*Calculate the average by dividing the summation of scores with the number of scores*/
average = (float)total / (float)num;
/*Print the output*/
fprintf(stdout, "The average of the entered scores is %f", average);
return;
}