+ 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

21st Feb 2019, 3:07 PM
Night_fury~
Night_fury~ - avatar
4 Respostas
+ 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"); }
23rd Feb 2019, 3:11 AM
John Wells
John Wells - avatar
+ 9
Pilla.Chandra Sekhar thanks for the answer bro..
25th Jun 2019, 1:54 AM
Night_fury~
Night_fury~ - avatar
+ 2
Switch statement is used for optional purpose
25th Jun 2019, 1:49 AM
CSP02
CSP02 - avatar
+ 2
That's ok
25th Jun 2019, 1:56 AM
CSP02
CSP02 - avatar