/**
* C program to calculate total, average and percentage of five subjects
*/
#include"stdio.h"
int main()
{
float n1, n2, n3, n4, n5;
float total, average, percentage;
// Read marks of all five subjects
printf("Enter marks of five subjects: \n");
scanf("%f%f%f%f%f", &n1, &n2, &n3, &n4, &n5);
// Calculate total, average and percentage one by one
total = n1 + n2 + n3 + n4 + n5;
average = total / 5.0;
percentage = (total / 500.0) * 100;
// Print the result
printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f \n", percentage);
return 0;
}
Enter marks of five subjects:
1 2 3 4 5
Total marks = 15.00
Average marks = 3.00
Percentage = 3.00Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.