Write a C program to input marks of five subjects of a student and calculate total, average and percentage of all subjects. How to calculate total, average and percentage of marks of five subjects in C programming. Logic to find total, average and percentage in C program.

**Example**

**Input**

Enter marks of five subjects: 95 76 85 90 89

**Output**

Total = 435 Average = 87 Percentage = 87.00

## Required knowledge

Fundamentals of C, Data types, Talking user input in C

## Logic to find total, average and percentage

Step by step descriptive logic to find total, average and percentage.

- Input marks of five subjects in some variables say eng, phy, chem, math and comp.
- Calculate sum of all subjects i.e. total = eng + phy + chem + math + comp.
- Divide total found above with 5 to get the average i.e. average = total / 5.
- Calculate percentage of student using percentage = (average / 500) * 100.
- Finally print values of all resultant variables total, average and percentage.

## Program to find total, average and percentage

```
/**
* C program to calculate total, average and percentage of five subjects
*/
#include <stdio.h>
int main()
{
float eng, phy, chem, math, comp;
float total, average, percentage;
// Input marks of all five subjects
printf("Enter marks of five subjects: \n");
scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);
// Calculate total, average and percentage
total = eng + phy + chem + math + comp;
average = total / 5.0;
percentage = (total / 500.0) * 100;
// Print all result
printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);
return 0;
}
```

**Important note:** Always use meaningful variable names. Use of variable name such as n1, num1, a is not recommended for this or any program.

Output

Enter marks of five subjects: 95 76 85 90 89 Total marks = 435.00 Average marks = 87.00 Percentage = 87.00

Happy coding 😉

### Recommended posts

- Basic programming exercises index.
- C program to find percentage and grade of a student.
- C program to find area of rectangle.
- C program to find diameter, circumference and area of circle.
- C program to calculate area of equilateral triangle.
- C program to calculate Simple Interest.
- C program to find sum of all array elements.

<pre><code> ----Your Source Code---- </code></pre>