You are on page 1of 3

8/7/13

C program to check whether input alphabet is a vowel or not | Programming Simplified

Home C programming C programming examples C program to check whether input alphabet is a vowel or not

C program to check whether input alphabet is a vowel or not

This code checks whether an input alphabet is a vowel or not. Both lower-case and upper-case are checked.

C programming code
# i n c l u d e< s t d i o . h > i n tm a i n ( ) { c h a rc h ; p r i n t f ( " E n t e rac h a r a c t e r \ n " ) ;
www.programmingsimplified.com/c/source-code/c-program-check-vowel 1/4

8/7/13

C program to check whether input alphabet is a vowel or not | Programming Simplified

s c a n f ( " % c " ,& c h ) ; i f( c h= =' a '| |c h= =' A '| |c h= =' e '| |c h= =' E '| |c h= =' i '| |c h= =' I '| |c h= = ' o '| |c h = = ' O '| |c h= =' u '| |c h= = ' U ' ) p r i n t f ( " % ci sav o w e l . \ n " ,c h ) ; e l s e p r i n t f ( " % ci sn o tav o w e l . \ n " ,c h ) ; r e t u r n0 ; }

Output of program:

Check vowel using switch statement


# i n c l u d e< s t d i o . h > i n tm a i n ( ) { c h a rc h ; p r i n t f ( " I n p u tac h a r a c t e r \ n " ) ; s c a n f ( " % c " ,& c h ) ; s w i t c h ( c h ) { c a s e' a ' : c a s e' A ' : c a s e' e ' : c a s e' E ' : c a s e' i ' : c a s e' I ' : c a s e' o ' : c a s e' O ' :
www.programmingsimplified.com/c/source-code/c-program-check-vowel 2/4

8/7/13

C program to check whether input alphabet is a vowel or not | Programming Simplified

c a s e' u ' : c a s e' U ' : p r i n t f ( " % ci sav o w e l . \ n " ,c h ) ; b r e a k ; d e f a u l t : p r i n t f ( " % ci sn o tav o w e l . \ n " ,c h ) ; } r e t u r n0 ; }

Function to check vowel


i n tc h e c k _ v o w e l ( c h a ra ) { i f( a> =' A '& &a< =' Z ' ) a=a+' a '-' A ' ; / *C o n v e r t i n gt ol o w e rc a s eo ru s ea=a+3 2* / i f( a= =' a '| |a= =' e '| |a= =' i '| |a= =' o '| |a= =' u ' ) r e t u r n1 ; r e t u r n0 ; }

This function can also be used to check if a character is a consonant or not, if it's not a vowel then it will be a consonant, but make sure that the character is an alphabet not a special character.

www.programmingsimplified.com/c/source-code/c-program-check-vowel

3/4

You might also like