Example : Implement a C code to take grade form user "A,B,C,D,F" and print "Excellent,Very Good,Good,Pass ,Failed" by using switch case.
C Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <stdio.h> #include <stdlib.h> int main() { char grade; printf("Please Enter Your Grade\n"); scanf("%s",&grade); switch (grade){ case 'A': case 'a': printf("Excellent!!\n"); break; case'B': case'b': printf("Very Good\n"); break; case'C': case'c': printf("Good\n"); break; case'D': case'd': printf("pass\n"); break; case'F': case'f': printf("Failed\n"); break; default: printf("Wrong Choice\n"); break; } return 0; } |
Output :
0 Comment to "Switch Case"
Post a Comment