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 Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 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;
} 
                        

🖥 Program 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 . . .
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.