Calculate Aggregate marks and Percentage marks
If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
float marks1, marks2, marks3, marks4, marks5, total, percentage;
printf("Enter the marks of first subject (out of 100)\t:");
scanf("%f",&marks1);
printf("Enter the marks of second subject (out of 100)\t:");
scanf("%f",&marks2);
printf("Enter the marks of third subject (out of 100)\t:");
scanf("%f",&marks3);
printf("Enter the marks of fourth subject (out of 100)\t:");
scanf("%f",&marks4);
printf("Enter the marks of fifth subject (out of 100)\t:");
scanf("%f",&marks5);
total = marks1 + marks2 + marks3 + marks4 + marks5;
percentage = (total * 100) / 500;
printf("\nAggregate marks = %f",total);
printf("\nPercentage is = %f",percentage);
getch();
}
Output
Enter the marks of first subject (out of 100) :56
Enter the marks of second subject (out of 100) :78
Enter the marks of third subject (out of 100) :89
Enter the marks of fourth subject (out of 100) :76
Enter the marks of fifth subject (out of 100) :98
Aggregate marks = 397.000000
Percentage is = 79.400002
Explanation
In the above program, marks of 5 subjects are taken as input from the user and stored in variables named 'marks1', 'marks2', 'marks3', 'marks4' and 'marks5' respectively using scanf() statement.
Aggregate marks is the total sum of all the marks obtained and is stored in variable named 'total' using the formula:
Percentage is calculated using the below formula:
Aggregate marks is the total sum of all the marks obtained and is stored in variable named 'total' using the formula:
total = marks1 + marks2 + marks3 + marks4 + marks5
Percentage is calculated using the below formula:
percentage = (total * 100) / 500