w3resource

C Exercises: Check whether an alphabet is a vowel or consonant


17. Vowel or Consonant Check

Write a C program to check whether an alphabet is a vowel or a consonant.

Visual Presentation:

Check whether an alphabet is a vowel or consonant


For more Practice: Solve these Related Problems:

  • Write a C program to check if an input alphabet is a vowel or consonant, handling both uppercase and lowercase letters.
  • Write a C program to determine vowel or consonant status without using a switch-case construct.
  • Write a C program to count the number of vowels and consonants in a given string.
  • Write a C program to check if a character is a vowel by comparing its ASCII value against vowel codes.

Sample Solution:

C Code:

#include <stdio.h>  // Include the standard input/output header file.

void main()  
{  
    char sing_ch;  // Declare a variable to store a single character.

    printf("Input any alphabet : ");  // Prompt user for input.  
    scanf("%c", &sing_ch);  // Read and store the character input.

    if(sing_ch=='a' || sing_ch=='e' || sing_ch=='i' || sing_ch=='o' || sing_ch=='u' || sing_ch=='A' || sing_ch=='E' || sing_ch=='I' || sing_ch=='O' || sing_ch=='U')  
    {  
        printf("The alphabet is a vowel.\n");  // Print message for vowel.
    }  
    else if((sing_ch>='a' && sing_ch<='z') || (sing_ch>='A' && sing_ch<='Z'))  
    {  
        printf("The alphabet is a consonant.\n");  // Print message for consonant.
    }  
    else  
    {  
        printf("The character is not an alphabet.\n");  // Print message for non-alphabet character.
    }   
}
 

Output:

Input any alphabet : K                                                                                        
The alphabet is a consonant. 

Flowchart:

Flowchart: Check whether an alphabet is vowel or consonant


Go to:


PREV : Character Type Classification.
NEXT : Profit and Loss Calculation.

C Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.