Thursday, March 3, 2016

switch case example in C

 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
#include<stdio.h>         //header file

main()            //main function
{
 char gradeName;         //variable declaration
 printf("Enter your Grade:");    
 scanf("%c",&gradeName);       //taking input from user
 
  switch(gradeName){       //start point of switch case
   case 'A':
   case 'a':
    printf("Excellent\n");
    break;
   case 'b':
   case 'B':
    printf("Good\n");
    break;
   case 'c':
   case 'C':
    printf("Less good\n");
    break;
   case 'd':
   case 'D':
    printf("Partially good\n");
    break;
   case 'f':
   case 'F':
    printf("Very bad\n");
   default:
    printf("Keyword not found\n");
    break;
  }            //end of switch case
}              //end of program

No comments:

Post a Comment

Thank you for commenting. Please wait for response :)