C Programming

Calculating Grade and total marks

This is perhaps the second most popular program after “Hello World”! Input marks for 5 subjects and calculate total marks and assign a corresponding grade.

Language : C

[sourcecode language='c']
#include
#include
void main()
{ int marks1,marks2,marks3,marks4,marks5,tmarks;
float avg;
char grade;

printf(“\nEnter the Marks of Subject1 : “);
scanf(“%d”, &marks1);
printf(“\nEnter the Marks of Subject2 : “);
scanf(“%d”, &marks2);
printf(“\nEnter the Marks of Subject3 : “);
scanf(“%d”, &marks3);
printf(“\nEnter the Marks of Subject4 : “);
scanf(“%d”, &marks4);
printf(“\nEnter the Marks of Subject5 : “);
scanf(“%d”, &marks5);

tmarks=marks1+marks2+marks3+marks4+marks5;
avg=tmarks/5;

printf(“Total marks are : %d”, tmarks);
printf(“The average is : %f”, avg);

if((avg>90)&&(avg>=80))
printf(“\nGrade is A!”);
else if((avg>80)&&(avg>=70))
printf(“\nGrade is B!”);
else if((avg>70)&&(avg>=60))
printf(“\nGrade is C!”);
else if((avg>=60)&&(avg>=50))
printf(“\nGrade is D!”);
else if((avg>50)&&(avg>=40))
printf(“\nGrade is E!”);
else
printf(“\nGrade is F!”);

getch();
}
[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal