Display percentage and grade using if - else if statement example sin c programming
/*How to write C Program to display percentage and grade using if - else if statement*/
#include
void main()
{
int m1,m2,m3,total;
float percent;
printf("Enter marks of three subjects:");
scanf("%d %d %d",&m1,&m2,&m3);
//Calculation of percent
total=m1+ m2 + m3;
percent=total/3;
printf("Percentage: %f\n",percent);
//Checking and displaying grade
if(percent>=70)
printf("----You have got Distinction----");
else if(percent>=60)
printf("----You have got First Class----");
else if(percent>=50)
printf("----You have got Second Class----");
else if(percent>=40)
printf("----You have got Pass Class----");
else
printf("----You have Failed----");
}
/*How to write C Program to display percentage and grade using if - else if statement*/
#include
void main()
{
int m1,m2,m3,total;
float percent;
printf("Enter marks of three subjects:");
scanf("%d %d %d",&m1,&m2,&m3);
//Calculation of percent
total=m1+ m2 + m3;
percent=total/3;
printf("Percentage: %f\n",percent);
//Checking and displaying grade
if(percent>=70)
printf("----You have got Distinction----");
else if(percent>=60)
printf("----You have got First Class----");
else if(percent>=50)
printf("----You have got Second Class----");
else if(percent>=40)
printf("----You have got Pass Class----");
else
printf("----You have Failed----");
}
0 comments: