Use else if with example (total of marks and percentage & Grade)
"else if"
It remove the above problem but it has own problem it check all the condition until one condition is true. So it is time consuming.
Syntax:-
If(condition1)
{
--------
}
else if(condition2)
{
-----
}
else
{
----------
}
Program
1.Calculate the total of marks and percentage & Grade
#include<stdio.h>
#include<conio.h>
void main()
{
float m,s,e,h,tot,per;
int max=400;
printf(“Enter the marks of Maths,Science,English,Hindi \n”);
scanf(“%f%f%f%f”,&m,&s,&e,&h);
tot=m+s+e+h;
per=tot/max*100;
printf(“Total=%f”,tot);
printf(“Percentage=%f”,per);
if(per>=60)
{
printf(“1 st Div”);
}
else if (per>=45)
{
printf(“2 nd div”);
}
else if (per>=33)
{
printf(“3rd Div”);
}
else
{
printf(“fail”);
}
getch();
}
Comments
Post a Comment