0:08 AM 2011-2012 question 2 |
write a program to read the student's grade , and print out his status according to the following
grade <50
50>= grade <65
65>= grade <75
75>= grade <85
85>= grade <=100
1- if-else
2- switch
if-else
#include"stdio.h"
main()
{
int grade;
printf("enter your grade : ");
scanf("%d", &grade);
if(grade>100 || grade<0){
printf("wrong grade !");
}else{
if(grade<50)
printf("fall");
else if(grade<65)
printf("pass");
else if(grade<75)
printf("good");
else if(grade<85)
printf("very good");
else
printf("excellent");
}
getch();
return 0;
}
switch
#include"stdio.h"
main()
{
int grade;
printf("enter your grade : ");
scanf("%d", &grade);
if(grade==100)
printf("excellent");
else{
switch(grade/5){
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
printf("fall");
break;
case 10:
case 11:
case 12:
printf("pass");
break;
case 13:
case 14:
printf("good");
break;
case 15:
case 16:
printf("very good");
break;
case 17:
case 18:
case 19:
printf("excellent");
break;
default:
printf("wrong grade !");
break;
}
}
getch();
return 0;
}
|
|
Total comments: 0 | |