C program to find the total, average, and percentage of five subjects
Program1:
#include<stdio.h>
Int main()
{
int chem,phy,eng,maths,bio;
float total,average,percentage;
//taking input
printf("Enter the marks of five subjects: \n");
scanf("%d%d%d%d%d", &chem, &phy, &eng, &maths, &bio);
//sum total
total= chem + phy + eng + maths + bio;
average = total / 5;
percentage = (total / 500) * 100;
//printing the values
printf("Total marks = %.2f \n", total);
printf("Average marks = %.2f \n", average);
printf("percentage = %.2f \n",percentage);
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output:
Enter the marks of five subjects:
98
88
76
90
73
Total marks = 425
Average marks = 85
Percentage = 85

You can also try this code with Online C++ Compiler
Run Code
In this program, we have taken input for the marks of five subjects and then performed arithmetic operations to find the total, average, and percentage of these subjects.
You can also read about dynamic array in c and Short int in C Programming
Program 2:
#include<stdio.h>
Int main()
{
int total_subjects;
float total,average,percentage,marks;
//taking input from the user
printf("Enter no. of subjects: \n");
scanf("%d", &total_subjects);
printf("Enter marks for 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 of %d Subjects = %0.2f\n",total_subjects,total);
printf("Average Marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output:
Enter no. of subjects:
6
Enter marks of each subject:
89
75
83
97
78
90
Total marks of 6 subjects = 512
Average Marks = 85.3
Percentage = 85.3

You can also try this code with Online C++ Compiler
Run Code
The above Program consists of fixed subjects, and in this Program, the user will flexibly choose the number of subjects and find total, average, and percentage marks. For finding the total, average, and percentage of subjects we have used arithmetic operators.
For better understanding implement code on C online compiler.
Must Read Decision Making in C
FAQs
1. What is the formula for calculating average?
Ans: The average is nothing but the sum of all terms divided by the total number of values. In the above example, the sum of all terms refers to the total number of marks, and the number of values refers to the total number of subjects.
Average = Total sum of values / Total number of values
2. What is the formula for calculating percentage?
Ans: Percentage = (Total sum of values / Total number of values *100) / 100
3. How to find total, average, and percentage?
Ans: suppose there are five fruits and the price of fruits are p1,p2,p3,p4,p5, then the total price of fruits will be p1 + p2 + p3 + p4 + p5.
And average = p1 + p2 + p3 + p4 + p5 / no. of fruits.
Percentage = (total / no. of fruits * 100 ) / 100
Using these formulae total,average and percentage can be found.
Key Takeaways
In this article, we have seen how to find the total, average, and percentage of five subjects using a C programming language. We have seen two different scenarios in program1; the subjects were defined already, and in program2, we have taken the no. of subjects from the user itself, to find the total, average, and percentage of five subjects.
Check out this problem - Subarray Sum Divisible By K
Also read reverse a number.
If we want to solve more such problems, you can visit Coding Ninjas Studio.
All the best for the future, and keep solving!