Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C++ program to check whether an Alphabet is Vowel or Consonant

C++ program to check whether an Alphabet is Vowel or Consonant|4 ways

Posted on March 5, 2022March 6, 2022

Table of Contents

  • C++ program to check whether an Alphabet is Vowel or Consonant
    • C++ Code to check whether Vowel or consonant
      • Code to check given Alphabet is Vowel or consonant using If else
      • Code to check given Alphabet is Vowel or consonant using Nested If
      • Code to check the Alphabet is Vowel or consonant using Ascii
      • Code to check the Alphabet is Vowel or consonant using switch

C++ program to check whether an Alphabet is Vowel or Consonant

In this article, we will discuss the concept of C++ program to check whether an Alphabet is Vowel or Consonant

In this post, we are going to learn how to write a program to  check whether given English alphabet is Vowel or Consonant using various ways in C++ language

C++ Code to check whether Vowel or consonant

Code to check given Alphabet is Vowel or consonant using If else

In this code, we are going to learn how to write a program to check  the given  English alphabet is Vowel or not using if-else and or operator in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    char ch;//Declare character variable ch

    cout<<"Enter an Alphabet: \n";
    //Ask input an Alphabet
    cin>>ch;
//Reading the Alphabet input from user
          //Checking both of lower case and upper case vowels using || (or) operator
          if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{//check vowel using if condition
  cout<<ch<<" is a vowel";//Display vowels
}
else{
  cout<<ch<<" is a consonant";//display consonant

}
getch();
    return 0;

}

When the above code is executed, it produces the following result

Case 1

Enter an Alphabet:
A
A is a Vowel

Case 2

Enter an Alphabet:
z
z is a Consonant

 

Code to check given Alphabet is Vowel or consonant using Nested If

In this code, we are going to learn how to write a program to check  the given  English alphabet is Vowel or consonant using Nested if-else and or operator in C++ language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    char ch;//Declare a character variable
    cout<<"Enter a character\n";//Ask input from the user
    cin>>ch;//Rea in put from the user
    if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){ //outer if use to check Alphabets

  if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{//inner if for checks vowels
  cout<<ch<<" is an vowel";//display vowels
}
else{//display consonant
cout<<ch<<" is a consonant";
}

}
else{
cout<<ch<<" is neither a vowel nor a consonant";
}

getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter an Alphabet:
I
I is a Vowel

Case 2

Enter an Alphabet:
b
b is a Consonant

 

Code to check the Alphabet is Vowel or consonant using Ascii

In this code, we are going to learn how to check  the given  English alphabet is Vowel or consonant using Ascii value in C++ language

Program 3

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    char ch;//Declare character variable ch

    cout<<"Enter an Alphabet: \n";
    //Ask input an Alphabet
    cin>>ch;
//Reading the Alphabet input from user
          //Checking both of lower case and upper case using || (or) operator
          if(ch==97||ch==101||ch==105||ch==111||ch==117||ch==65||ch==69||ch==73||ch==79||ch==85)
{//check vowel using if condition
  cout<<ch<<" is an vowel";//Display vowels
}
else{
  cout<<ch<<" is a consonant";//display consonant

}
getch();
    return 0;

}

When the above code is executed, it produces the following result

Case 1

Enter an Alphabet:
I
I is a Vowel

Case 2

Enter an Alphabet:
b
b is a Consonant

 

Code to check the Alphabet is Vowel or consonant using switch

In this code, we are going to learn how to check  the given  English alphabet is Vowel or consonant using switch statements in C++ language

Program 4

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
  char ch;
    cout<<"Enter any Alphabets: ";
    cin>>ch;

    switch(ch){
case 'a':
    cout<<'a'<<" is Vowel";
    break;

    case 'e':
   cout<<'e'<< " is Vowel";
    break;

     case 'i':
   cout<<'i'<< " is Vowel";
    break;

     case 'o':
   cout<<'o'<< " is Vowel";
    break;

     case 'u':
   cout<<'u'<< " is Vowel";
    break;

case 'A':
    cout<<'A'<< " is Vowel";
    break;

    case 'E':
   cout<<'E'<< " is Vowel";
    break;

     case 'I':
   cout<<'T'<< " is Vowel";
    break;

     case 'O':
   cout<<'O'<< " is Vowel";
    break;

     case 'U':
   cout<<'U'<< " is Vowel";
    break;

    default:
        cout<<ch<<" is consonant";
    break;
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter any Alphabet:
u
u is a Vowel

Case 2

Enter any Alphabet:
b
b is a Consonant

 

Suggested post

If else statement in C++

Nested if statement in C++

Operator in C++ language

Switch statements in C++ language

 

Similar post

Java program to print all alphabets in given range

C program to print all alphabets in given range

C++ program to print all alphabets in given range

 

Java program to print all alphabets using loops

C program to print all alphabets using loops

C++ program to print all alphabets using loops

 

Java program to check whether a character is Alphabet or Not

C++ program to check whether a character is Alphabet or Not

C program to check whether a character is Alphabet or Not

Python program to check whether a character is Alphabet or Not

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes