You're online now.

Hurray! you are online now.

Write a C program to check alphabet is vowel or consonant

This program checks whether a given alphabet is a vowel or a consonant.

// write a c program to check a given alphabet is a vowel or a consonant.
    #include<stdio.h>
    int main(){
        char ch;
        printf("Enter the alphabet : ");
        scanf("%c", &ch);
        if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
            printf("Vowels");
        }else{
            printf("Consonant");
        }
        return 0;
    }
#include<stdio.h>

#include<stdio.h> is a preprocessor directive that includes the standard input/output library in the program. This library provides function for input and output operation, such as ‘printf()’ and ‘scanf()’, which are used in this program to print messages on the console and read input from the user.

int main(){

This function takes an alphabet input from the user and determines whether it is a vowel or a consonant. The ‘main()’ function is returning an integer value of 0. This is the standard convention in C programming to indicate that the program has executed successfully.

char ch;

‘char ch;’ is declaring a variable names ‘ch’ of type ‘char’. This variable will be used to store the alphabet entered by the user.

printf("Enter the alphabet : ");

The above line of code is printing a message on the console asking the user to enter an alphabet.

scanf("%c", &ch);

‘scanf("%c", &ch);’ is reading a character input from the user and storing it in the variable ‘ch’. The ‘%c’ format specifier is used to read a single character input from the user. The ‘&’ operator is used to get the address of the variable ‘ch’, whic is required by ‘scanf()’ to store the input value iin the variable.

if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
        printf("Vowels");
    }else{
        printf("Consonant");
    }

This block of code is checking whether the character entered by the user is a vowel or a consonant. If the character is a vowel (either lowercase or uppercase), the program prints “Vowels”. Otherwise, if the character is a consonant (any character other that a vowel), the program prints “Consonant”.

return 0;
    }

return 0, which indicates that the program has executed successfully.

🖤 0
Buy me coffee ☕

Comments

Oops!

No comments here...