# Total, average and % of 5 subjects in C

yuvatimankar
Last Updated: Mar 23, 2023

## Problem

Write a C program to take input of 5 subjects and find the total, average, and percentage of subjects. In this program, we will be using arithmetic operations.

## Logic

• For finding total, average, and percentage we are using arithmetic operations.
• First of all, we have to take inputs of 5 subjects and store them in some variables, say phy, eng, maths, chem, bio.
• Create another variable named total, add all the subjects and store the result in the total variable.
• To find the average, divide the total by the sum of all subjects.
• For finding percentage, use the formula percentage=(average/500)*100.
• At last, print the values of the total, average, and percentage.

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

Output:

``````Enter the marks of five subjects:
98
88
76
90
73
Total marks = 425
Average marks = 85
Percentage = 85``````

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.

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

}``````

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``````

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.

## 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

If we want to solve more such problems, you can visit codestudio.

All the best for the future, and keep solving!