C program to check vowel or consonant

C program to check vowel or consonant


C program to check vowel or consonant 

The required knowledge to understand this program 

if statement in C

else if ladder

Program

//write a c program to check vowel or consonant

#include<stdio.h>

#include<conio.h>

void main()

{

     char chr;

     printf("\n Enter a character: ");

     scanf("%c", &chr);

     //first checking upper-case letters   

     if(chr=='A'||chr=='E'||chr=='I'||chr=='O'||chr=='U')

     {

          printf("\n %c is a vowel", chr);

     }

     //checking lower-case letters

     else if(chr=='a'||chr=='e'||chr=='i'||chr=='o'||chr=='u')

     {

          printf("\n %c is a vowel", chr);

     }

     else{

          printf("\n %c is a consonant", chr);

     }

}

 

 Download code

Output

c_program_to_check_vowels


  • In this program, the program get alphabet from the user and stored in chr variable

  • if(chr=='A'||chr=='E'||chr=='I'||chr=='O'||chr=='U') condition checks the uppercase vowels letter and || is Or operator

  • printf("\n %c is a vowel", chr); display the chr is a vowel
 
  • else if(chr=='a'||chr=='e'||chr=='i'||chr=='o'||chr=='u') checks the lower case vowels letter.
 
  • printf("\n %c is a vowel", chr); it also display chr is a vowel
 
  • If char is not a vowels letter then printf("\n %c is a consonant", chr); print chr is a vowel

 

Post a Comment

0 Comments