  Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email  Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

# C Program to Calculate Percentage of 5 Subjects

Last Updated on April 12, 2023 by Prepbytes Calculating percentages is a common task in academic settings, and it can be done easily using programming languages like C. Here we will discuss the C program to calculate the percentage of 5 subjects. This program will take input from the user for the marks obtained in each subject and will then calculate and display the percentage. This program can be useful for students or teachers who need to quickly calculate percentages for multiple students.

Calculating the percentage of 5 subjects is not a complicated task, you just have to sum up all the marks and perform multiplication with 100 on it. After that, divide it by the total maximum marks a student can obtain. At last, you will get the result as the percentage of the 5 subjects.

## Algorithm to Write C Program to Calculate Percentage of 5 Subjects

• Read five subject marks and store them into 5 different variables.
• Calculate the sum of all subjects and store in total = eng + phy + chem + math + comp.
• Divide the sum of all subjects by the total number of subjects to find the average i.e. average = total / 5.
• Calculate the percentage using percentage = (total / 500) * 100.
• Finally, print resultant values total, average, and percentage.

## Code Implementation for C Program to Calculate Percentage of 5 Subjects

```#include <stdio.h>

int main()
{
float eng, phy, chem, math, comp;
float total, average, percentage;

printf("Enter marks of five subjects: :- ");
scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);

total = eng + phy + chem + math + comp;
average = total / 5.0;
percentage = (total / 500.0) * 100;

printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);

return 0;
}
```

Explanation
In the above C program, we calculate the percentage of marks obtained by a student in five subjects – English, Physics, Chemistry, Mathematics, and Computer Science. The given C program calculates the percentage of marks obtained by a student in five subjects – English, Physics, Chemistry, Mathematics, and Computer Science. It prompts the user to enter the marks obtained in each subject and then calculates the total marks, average marks, and percentages using appropriate formulae. The program uses scanf() to read the input values and printf() to display the calculated values up to two decimal places. This program can be useful for students or teachers who need to quickly calculate the percentage of marks obtained by a student in five subjects.

### Time Complexity

O(1) will be the time complexity for the c program to calculate the percentage of 5 subjects as it requires mathematical calculations.

Conclusion
Hoping this article has discussed c program to calculate the percentage of 5 subjects will give you a clear idea for that. For the starting phase of the coding career, problems like calculating the percentage of 5 subjects will build your logic and confidence which will encourage you to solve more coding questions.

Q1. What formulae are used in this program to calculate the total marks, average marks, and percentage?
Ans. The total marks are calculated by adding the marks obtained in each subject. The average marks are calculated by dividing the total marks by 5.0, and the percentage is calculated by dividing the total marks by 500.0 (the maximum marks for all five subjects combined) and multiplying the result by 100.

Q2. What data types are used in this program?
Ans. Float data type is used to store the marks obtained in each subject and the calculated values of total marks, average marks, and percentages.

Q3. Can this program be used to calculate the percentage of marks obtained in more than five subjects?
Ans. No, this program is specifically designed to calculate the percentage of marks obtained in five subjects only. If you need to calculate the percentage of marks obtained in more subjects, you will need to modify the program accordingly.

Q4. How to find the percentage of marks?
Ans. To find the percentage of marks, you need to know the total marks obtained in a particular subject or set of subjects and the maximum marks that can be obtained in those subjects. Once you have these values, you can use the following formula to calculate the percentage:
Percentage = (Total Marks / Maximum Marks) x 100