
II-88 Programming Concepts
Below given program is the same program as of the above program using switch statement
instead of multiple if-else statement.
scanf(" %c",&x);
if(x=='a')
printf("\nYou have pressed Alphabet 'a'");
else if(x=='b')
printf("\nYou have pressed Alphabet 'b'");
else if(x=='c')
printf("\nYpu have pressed Alphabet 'c'");
else
printf("\nSorry You have pressed Alphabet other than
(a,b,c):");
getch();
}
OUTPUT:
Enter any alphabet from (a,b,c):b
You have pressed Alphabet 'b'
#include <stdio.h>
#include <conio.h>
void main()
{
char x;
clrscr();
printf("\nEnter any alhabet from (a,b,c)");
scanf(" %c",&x); ...