Wednesday, 10 September 2014

C Language Program for finding vowel or consonant using switch statement with Example



Here is a C program for finding a particular alphabet entered by the user is consonant or vowel by using the switch statement. The sample program is given below.



Write a C source code for finding a given character is vowel or consonant
 or
VOWEL OR CONSTANT C PROGRAM:

//Header files
#include<stdio.h>
#include<conio.h>
 
void main()
{
    //Program variables
    char letter;
 
    clrscr();//function to clear previous output
 
    printf("Enter the letter : ");//Display function
    scanf("%c",&letter);//Getting input function
//  if((letter>'a' && letter<'z')||(letter>'A' && letter<'Z'))//Conditional statement
  //    {
        switch(letter) //Switch statement
        {
            case 'a' :
            case 'e' :
            case 'i' :
            case 'o' :
            case 'u' :
            case 'A' :
            case 'E' :
            case 'I' :
            case 'O' :
            case 'U' :printf("Character is vowel");
                 break;
            default: printf("Character is consonant");
                 break;
        }
    //  }
     // else
       //       printf("Character is incorrect");
 
    getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.