Become Our Fan on Social Sites!

Facebook Twitter

Google+ RSS YouTube

Wednesday 2 October 2013

C program to check character is a vowel or not

There are five vowels like 'a',  'e', 'i',  'o', and 'u'. Following C program checks that inputted character is vowel or not.  



1) Using if condition 

 #include <stdio.h>    
  int main()    
  {    
    char ch;    
    printf("Enter One Character : ");    
    scanf("%c", &ch);    
    if(ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' ||  
      ch=='O' || ch=='o' || ch=='U' || ch=='u')   
    {   
      printf("Character is a Vowel");    
    }   
    else   
    {   
      printf("Character is not a Vowel");   
    }   
    return 0;    
  }   

2) Using switch case

 #include <stdio.h>   
  int main()   
  {   
   char ch;   
   printf("Enter One Character : ");   
   scanf("%c", &ch);   
   switch(ch)   
   {   
    case 'a':   
    case 'A':   
    case 'e':   
    case 'E':   
    case 'i':   
    case 'I':   
    case 'o':   
    case 'O':   
    case 'u':   
    case 'U':   
     printf("Character is a Vowel");   
     break;   
    default:   
     printf("Character is not a Vowel");   
   }   
   return 0;   
  }   

0 comments :

Post a Comment