Pages

Saturday, December 28, 2013

Switch Statement

Write program that input a character from user and checks whether it’s a Vowel or a Consonant 


Input:

 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
 #include <stdio.h>
 #include <conio.h>
 void main(void)
 {
  clrscr();
  char ch;
   printf("Enter an Alphabet:  ");
    ch = getche();
   switch(ch)
   {
 case 'a':
 case 'A':
    printf("\n It's a vowel");
  break;
 case 'e':
 case 'E':
   printf("\n It's a vowel");
  break;
 case 'i':
 case 'I':
   printf("\n It's a vowel");
  break;
 case 'o':
 case 'O':
   printf("\n It's a vowel");
  break;
 case 'u':
 case 'U':
   printf("\n It's a vowel");
  break;
       default:
   printf("\n It's not a vowel");
  break;
  }
 getch();
 }// main

Result:

Case 1(if it’s vowel):
Enter an Alphabet:  A
It's a vowel

Case 2(if it’s not vowel):
Enter an Alphabet:  H
It's not a vowel

No comments:

Post a Comment