Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to make a program that calculate average score

+2 votes
asked Nov 15, 2018 by Fakharudin Badron (140 points)

1 Answer

0 votes
answered Nov 15, 2018 by Sumant Marathe (140 points)

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;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...