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, consonant, number or special character

Input - Output

Input
Enter a character : E

Output
E is a vowel

Input
Enter a character : 8

Output
8 is an integer

Algorithm

Step 1: START

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

Step 3: Check the condition:

    if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')

      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

   else if(ch>=48 &&ch<=57)

       print it is an integer

   else

       print It is a special character

Step 4: END

CODE


/* Check a character is vowel,consonant or special character */
#include  <stdio.h>
int main()
{
      char ch;
      printf(" Enter a character : ");
      scanf("%c",&ch);
      if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')
          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);
      else if(ch>=48 &&ch<=57)
          printf(" %c is an integer",ch);
      else
          printf(" %c is a special character ",ch);
    return 0;
}


/* Check a character is vowel,consonant or special character */
#include <iostream>
using namespace std;
int main()
{
      char ch;
      cout<<" Enter a character: ";
      cin>>ch;
      if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')
          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";
      else if(ch>=48 &&ch<=57)
          cout<<ch<<" is an integer";
      else
          cout<<ch<<" is a special character";
    return 0;
}

OutPut

Enter a character : 8

8 is an Integer