C program to check whether an alphabet is vowel or consonant



C program to check whether an alphabet is vowel or consonant

Here we will to find whether a character is an vowel or consonant, to find first we are taking a character input from user and store it in variable 'c' which is of char datatype. Then we are initializing two variables with all the vowels as shown in the below program. Then we will check if it is present, if yes then it is vowel else it is a consonant.

Algorithm:-

  1. Start
  2. Input character
  3. Initialize l and u
  4. Check if its present
  5. Print result
  6. Stop.

Vowels:-

In English, the word vowel is commonly used to refer both to vowel sounds and to the written symbols that represent them (a, e, i, o, u, and sometimes y).
Basically vowel are a, e, i, o, u.

Consonants:- 

In English, consonants are letters other than vowels.

Program:-

Here, In this simple program we are checking if the given alphabet is consonant or vowel. First we are asking user to enter a alphabet and in the variable 'l' and 'u' we define the vowels in lowercase and uppercase respectively. Then we have if-else statements, if the letter entered by the user is a vowel then print the letter entered by the user is a vowel otherwise the letter is consonant. Refer the program given below


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

 Output:-
 Enter a character: i
 i is a vowel.
 
 Enter a character: w
 w is a consonant.

Post a Comment

0 Comments