45 : C Program to Check Entered char is a Vowel or Consonant

Check out the complete list of c-programs : C Program List    



This program reads in a char value from the console and checks if its a Vowel or a Consonant. If the char is 'a','e','i','o' or 'u' than its a vowel else its a consonent.

We also need to check upper cases and lower cases (ie A E I O U).

We can use if else or switch-case statement to achieve this.

Variables :

ch : Datatype char : Holds value of number inputted by the user. %c is the Format specifier for char's








/*
 * 1000+ C programs + tutorials
 *
 * 
 * 40_check_entered_char_is_a_vowel_or_consonant.c
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include 
//#include 



void main() {

char ch;
  

//clrscr();

    printf("C Program to Find Entered Character is a Vowel or Consonant.");

    printf("\n\n Enter Number : ");
    scanf("%c", &ch);

    

     
     
  //Logic to find Vowel/Consonant

   if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
      ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' ) {
          
         printf("\n\n %c is a Vowel!! ",ch);
  
  }
   else {
       
         printf("\n\n %c is a Consonant!! ",ch);
   }
   
   
 
//    getch();



}






Using Switch-Case


/*
 * 1000+ C programs + tutorials
 *
 * 
 * 40_check_entered_char_is_a_vowel_or_consonant.c
 *
 * Using Switch-Case
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include 
//#include 



void main() {

char ch;
  

//clrscr();

    printf("C Program to Find Entered Character is a Vowel or Consonant.");

    printf("\n\n Enter Number : ");
    scanf("%c", &ch);

    

     
     
  //Logic to find Vowel/Consonant

switch(ch)  {

     case 'a' || 'e' || 'i' || 'o' || 'u' :
          printf("\n\n %c is a Vowel!! ",ch);
     break;
     
    case 'A' || 'E' || 'I' || 'O' || 'U' :
          printf("\n\n %c is a Vowel!! ",ch);
     break;
     
   default:
       printf("\n\n %c is a Consonant!! ",ch);

}

 
//    getch();



}












The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.