C Program To Find Total, Average, and Percentage of Five Subjects

In this post, we will learn how to find the total, average, and percentage of five subjects using C Programming language.

C Program To Find Total, Average, and Percentage of Five Subjects

In the program, the marks of five subjects are taken as input from the user. And then the average and percentage of five marks is calculated using the standard formula.

So, without further ado, let’s begin this tutorial.

C Program To Find Total, Average, and Percentage of Five Subjects

// C Program To Find Total, Average, and Percentage of Five Subjects
#include <stdio.h>
int main(){
    int English, Maths, Science, Psychology, History;
    float total, average, percentage;
    
    // Asking for Input
    printf("Enter the marks of English, Maths, Science, Psychology and History: \n");
    scanf("%d %d %d %d %d", &English, &Maths, &Science, &Psychology, &History);
    
    total = English + Maths + Science + Psychology + History;
    average = total / 5;
    percentage = (total/500) * 100;
    
    printf("Total Marks of the Student: %.2f\n", total);
    printf("Average Marks of the Student: %.2f\n", average);
    printf("Percentage of the Student: %.2f\n", percentage);
    return 0;
}

Output

Enter the marks of English, Maths, Science, Psychology and History: 
92 85 90 86 84
Total Marks of the Student: 437.00
Average Marks of the Student: 87.40
Percentage of the Student: 87.40

How Does This Program Work ?

    int English, Maths, Science, Psychology, History;
    float total, average, percentage;

In this program, we have declared five int data type variables which will store the marks of different subjects.

We have also declared three float data type variables which will store total marks of the student, average of the total marks and percentage of the total marks.

    total = English + Maths + Science + Psychology + History;
    average = total / 5;
    percentage = (total/500) * 100;

We calculate the total, average and percentage of the subjects using the average formula. 

  • Total Marks = Sum of all Marks 
  • Average = Total Marks / Total No. of Subjects
  • Percentage = (Marks Obtained / 500) * 100
    printf("Total Marks of the Student: %.2f\n", total);
    printf("Average Marks of the Student: %.2f\n", average);
    printf("Percentage of the Student: %.2f\n", percentage);

Finally, the total marks, average marks and percentage of the subjects is printed to the screen using printf() function. Here, we have used %.2f format specifier because we want to display the result only till 2 decimal places.

C Program To Find Total, Average, and Percentage of N Subjects

// C Program To Find Total, Average, and Percentage of N Subjects
#include <stdio.h>
int main(){
    int total_subjects, i;
    float marks, total = 0, average, percentage;
    
    printf("Enter total number of subjects: \n");
    scanf("%d", &total_subjects);
    printf("Enter marks of each subject: \n");
    for (int i = 0; i < total_subjects; i++){
        scanf("%f", &marks);
        total = total + marks;
    }
    average = total / total_subjects;
    percentage = (total / (total_subjects * 100)) * 100;
    
    printf("Total Marks: %.2f\n", total);
    printf("Average Marks: %.2f\n", average);
    printf("Percentage: %.2f", percentage);
    return 0;
}

Output

Enter total number of subjects: 
7
Enter marks of each subject: 
70
68
90
86
82
77
95
Total Marks: 568.00
Average Marks: 81.14
Percentage: 81.14

Conclusion

I hope after going through this post, you understand how to find the total, average, and percentage of five subjects using C Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published.