Alphabet

Program to Check whether an Alphabet is vowel or consonant in C++

Program to Check whether an Alphabet is a vowel or consonant in C++

In this article, we will discuss the concept of Program to Check whether an Alphabet is a vowel or consonant in C++ programming language

In this post, we are going to learn how to find whether the given alphabet is vowel or consonant in C++ language

Check whether vowel or not

Program to find whether an alphabet is a vowel or consonant

Program to find whether an alphabet is a vowel or consonant using if-else

Program 1

The program allows the user to enter an Alphabet thereafter it will  check and display the result of the given Alphabet whether it is a vowel or consonant using the if-else statements in C++ programming language

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

    cout<<"Enter an Alphabet\n";
    cin>>ch;//Takes character input from the user

          //Checking both of lower case and upper case using || (or) operator
          if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{
    cout<<ch<<" is vowel";//Display vowels
}
else{
    cout<<ch<<" is  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 vowel

 

case 2

Enter an Alphabet
i
i is vowel

 

case 3

Enter an Alphabet
S
S is consonant

 

case 4

Enter an Alphabet
h
h is consonant

 

Approach

  • In the program, the user is asked to enter an Alphabet and entered Alphabet is stored in character variable ch
  • The program evaluates whether the entered Alphabet is a vowel or consonant, using if-else statements
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not vowel it will display”it is consonant”

 

program to find whether an Alphabet is a vowel or consonant using if-else if else

Program 2

The program allows the user to enter an Alphabet thereafter it will  check and display the result of the given Alphabet whether it is a vowel or consonant using the if else-if else statements in C++ programming language

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

int main()
{
    char ch;
    cout<<"Enter a character\n";
    cin>>ch;//Takes character input from the user
    if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{//if statements checks vowels
    cout<<ch<<" is vowel";
}
else if//else if statement checks consonant
((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){
    cout<<ch<<"  is  consonant";
}
else{
cout<<ch<<" is not an alpabet";
}
getch();
    return 0;
}

 

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

case 1

Enter an Alphabet
E
E is vowel

 

case 2

Enter an Alphabet
u
u is vowel


case 3

Enter an Alphabet
L
L is consonant

 

case 4

Enter an Alphabet
h
h is consonant

 

Case 5

Enter an Alphabet
@
@ is not an Alphabet

 

Approach

  • In the program, the user is asked to enter an Alphabet and entered Alphabet is stored in character variable ch
  • The program evaluates whether the entered Alphabet is a vowel or consonant, using if-else-if else statements
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not vowel it will display”it is consonant”

 

program to find whether an Alphabet is a vowel or consonant using Nested if-else

Program 3

The program allows the user to enter an Alphabet thereafter it will  check and display the result of the given Alphabet whether it is a vowel or consonant using the Nested  if-else statements in C++ programming language

 

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

int main()
{
    char ch;
    cout<<"Enter a character\n";
    cin>>ch;//Takes caracter input from the user
    if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){ //outer if use to check consonant

    if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{//inner if statements checks vowels
    cout<<ch<<" is vowel";
}
else{//display consonant
cout<<ch<<" is 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
E
E is vowel


case 2

Enter an Alphabet
u
u is vowel

 

case 3

Enter an Alphabet
L
L is consonant

 

case 4

Enter an Alphabet
h
h is consonant

 

Case 5

Enter an Alphabet
@
@ is not an Alphabet

 

Approach

  • In the program, the user is asked to enter an Alphabet and entered Alphabet is stored in character variable ch
  • The program evaluates whether the entered Alphabet is a vowel or consonant, using Nested if-else statements
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not vowel it will display”it is consonant”

 

Suggested for you

The operator in C++ language

Data type in C++ language

Variable in C++ language

If-else statements in C++ Language

 

Similar post

C code to check whether the Alphabet is vowel or consonant

Python code to check whether the Alphabet is vowel or consonant

Java  code to check whether the Alphabet is vowel or consonant

 

C code to check whether the character is Alphabet or not

C++ code to check whether the character is Alphabet or not

Java code to check whether the character is Alphabet or not

Python code to check whether the character is Alphabet or not

 

 

Program to Check whether an Alphabet is vowel or consonant in Java
Check whether an Alphabet is vowel or consonant in C language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago