+ 3
Use of switch statement
can we write a code to check one's result if pass, fail or not appeared in exam using switch statement .?\n i was able to do it using if-else statement: https://code.sololearn.com/c7QYuG0dUqY7/#c
4 Réponses
+ 3
C switch statements require listing each value so one hundred case labels to use it here. Now, if you could use a/10 to have ten case labels, it might be fine.
switch ((a-1)/10) {
case 9:
printf("you are in top one percent");
break;
case 8:
case 7:
case 6:
case 5;
printf("you passed");
break;
case 4:
case 3:
case 2;
case 1:
case 0:
printf("you failed!");
break;
default:
printf("invalid score\n");
}
+ 9
Pilla.Chandra Sekhar thanks for the answer bro..
+ 2
Switch statement is used for optional purpose
+ 2
That's ok