Home / Programs / Accept a character from the user and find it is a vowel or not without using any loop
Programming Example

Accept a character from the user and find it is a vowel or not without using any loop

👁 1,226 Views
💻 Practical Program
📘 Step by Step Learning
Accept a character from the user and find it is a vowel or not without using any loop

Program Code

// Accept a character from the user and find it is a vowel or not without using any loop
#include <stdio.h>
int main()
{
    char c;
    int isLVowel, isUVowel;

    printf("Enter an alphabet: ");
    scanf("%c",&c);

    
    isLVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

    
    isUVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

    
    if (isLVowel || isUVowel)
        printf("%c is a vowel.", c);
    else
        printf("%c is a consonant.", c);
    return 0;
}

Output

Enter an alphabet: e
e is a vowel.
Press any key to continue . . .

Explanation

This program uses the concept of if statement

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.