Home »
C solved programs »
C basic programs
C program to read marks and print percentage and division
In this C program, we are going to read marks in 3 subjects, we will find the total, percentage and print the division based on the percentage.
Submitted by Manju Tomar, on October 09, 2017
Problem statement
Given (or input from the user) marks in 3 subjects and we have to calculate parentage and print the division.
Formula to get percentage
Formula to get percentage: Total obtained marks *100/Grand total (total of maximum marks)
Conditions to find division
Division
Based on the percentage, we will print the division, if percentage is:
- Greater than or equal to 60, division will be "First"
- Greater than or equal to 50, division will be "Second"
- Greater than or equal to 40, division will be "Third"
- Less than it (we will not check any condition, it will be written in else), the result will be fail
C program to read marks and print percentage and division
#include<stdio.h>
int main() {
int science;
int math;
int english;
int total;
float per;
science = 50;
math = 90;
english = 40;
//you can take input from user instead of these values
//calculating total
total = science + math + english;
//calculating percentage
per = (float) total * 100 / 300;
printf("Total Marks: %d\n", total);
printf("Percentage is: %.2f\n", per);
//checking division and printing
if (per >= 60) {
printf("First division\n");
} else if (per >= 50) {
printf("Second division");
} else if (per >= 40) {
printf("Third division");
} else {
printf("Fail\n");
}
return 0;
}
Output
Total Marks: 180
Percentage is: 60.00
First division
This is a simple C program, if you are a beginner you will learn to calculate total, percentage and how to find division (example of multiple if else).
If liked or any issue with the program, feel free to leave your comment.
C Basic Programs »