C Program to Calculate Percentage and Class Based on Marks
Subject: PPS (Programming for Problem Solving)
Contributed By: Sanjay
Created At: February 3, 2025
Question:
Write a C Program to Calculate Percentage and Class Based on Marks
Explanation Video:

Explanation:
We take 5 subject marks and find the percentage.
Based on percentage, print the class.
Source Code:
#include <stdio.h>
int main() {
int marks[5], i, total = 0;
float percentage;
printf("Enter marks of 5 subjects: ");
for (i = 0; i < 5; i++) {
scanf("%d", &marks[i]);
total += marks[i];
}
percentage = (total / 5.0);
printf("Percentage: %.2f%%\n", percentage);
if (percentage >= 60)
printf("First class\n");
else if (percentage >= 50)
printf("Second class\n");
else if (percentage >= 40)
printf("Third class\n");
else
printf("Fail\n");
return 0;
}
Input:
Enter marks of 5 subjects: 60 70 80 50 40
Output:
Percentage: 60.00%
First class