PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to check whether a character is vowel or consonant

Input - Output

Input
Enter a character : E

Output
E is a vowel

Input
Enter a character : p

Output
p is a consonant

Algorithm

Step 1: START

Step 2: Enter an alphabet 'ch' as an input.

Step 3: Check the condition:

    if the character is “A, E, I, O, U” or “a, e, i, o, u”

      print the character is vowel

   else

      print the character is consonant

Step 4: END

CODE


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


/* Check an alphabet is vowel or consonant */
#include <iostream>
using namespace std;
int main()
{
      char ch;
      cout<<" Enter a character: ";
      cin>>ch;
      if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
          cout<<ch<<" is a vowel";
      else
          cout<<ch<<" is a consonant";
    return 0;
}

OutPut

Enter a character : p

p is a consonant