check an alphabet is vowel or not in C using if else ?


Q.) W.A.P to check an alphabet is vowel or not in C using if else ?
 #include<stdio.h>
 #include<conio.h>
 int main()
 {
     char c;
     printf("Enter an alphabet: ");
     scanf("%c",&c);
    if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U'){
       printf("%c is a vowel.",c);
    }
  else{
       printf("%c is a consonant.",c);
  }
  getch();
}
Output
Enter an alphabet :
b     /* say c = b */
b is a consonant.

Program Explanation


Step 1: Include header files (#include<stdio.h> and #include<conio.h>).

Step 2: Start with main function with return type.

Step 3: parenthesis to start and end the program { }.

Step 4: declare variables with data type i.e, 'c' is a character type so we use "char" data type.

Step 5: Use output function printf() to print the output on the screen.

Step 6: Use input function scanf() to get input from the user.

Step 7: Here, we have to check whether the entered alphabet is vowel or consonant using if-else condition, Here,the assignment operator (i.e, ==) to check condition. if condition checks whether entered character is an alphabet or a consonant.

  • if this condition is true, then it will execute if block, which will print the output as "entered alphabet" is a vowel.
  • if the condition is not true, then it will execute else block and print the output as "entered alphabet" is a consonant.
Step 8: using getch() function to hold the screen.