Home / Programs / C program to calculate total average and percentage of five subjects
Programming Example

C program to calculate total average and percentage of five subjects

👁 3,587 Views
💻 Practical Program
📘 Step by Step Learning
Study this program carefully to understand the logic, output, and explanation in a structured way.

Program Code

/**
 * 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;
} 

Output

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

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.