Alphabet

Check whether an Alphabet is vowel or consonant in C language

Check whether an Alphabet is a vowel or consonant in C language

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 and the given alphabet is vowel or consonant in c language

vowel or not

Check 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 <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;

    printf("Enter an Alphabet\n");
    scanf("%c",&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')
{
    printf("%c is vowel",ch);//Display vowels
}
else{
    printf("%c  is  consonant",ch);//display consonant

}
getch();
    return 0;

}

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

case 1

Enter an Alphabet
A
A is vowel


case 2

Enter an Alphabet
e
e is vowel

 

case 3

Enter an Alphabet
H
H is consonant

 

case 4

Enter an Alphabet
m
m 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 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 a vowel it will display”it is consonant”

 

 

 

Check 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 statements in C programming language

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("Enter a character\n");
    scanf("%c",&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
    printf("%c is vowel",ch);//display vowel
}
else if//else if statement checks consonant
((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){
    printf("%c is  consonant",ch);//display consonamt
}
else{
printf("%c is not an alpabet",ch);//display non-alphabet
}
getch();
    return 0;
}

 

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

case 1

Enter a character
A
A is vowel

 

case 2

Enter a character
i
i is vowel

 

case 3

Enter a character
G
G is consonant

 

case 4

Enter a character
j
j is consonant

 

case 5

Enter a character
&
& is not 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 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 a vowel it will display”it is consonant”

 

Check 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 <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("Enter a character\n");
    scanf("%c",&ch);
    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
    printf("%c is vowel",ch);
}
else{//display consonant
printf("%c is consonant",ch);
}

}
else{
printf("%c is neither a vowel nor a consonant",ch);
}//display non-alphabet

getch();
    return 0;
}

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

case 1

Enter a character
U
U is vowel

 

case 2

Enter a character
o
o is vowel

 

case 3

Enter a character
D
D is consonant

 

case 4

Enter a character
j
j is consonant

 

case 5

Enter a character
&
& is nither a vowel nor a 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 vowel or consonant using Nested if statements
  • If the given Alphabet is a vowel The program displays the output “it is a vowel” and if the given Alphabet is not a 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

Python code to check whether the Alphabet is vowel or consonant

C++ 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

 

Java program to print all upper case and lower case Alphabets

C++ program to print all upper case and lower case Alphabets

C program to print all upper case and lower case Alphabets

 

Java code to print all upper case and lower case Alphabets between the given range

C++ code to print all upper case and lower case Alphabets between the given range

C code to print all upper case and lower case Alphabets between the given range

 

Program to Check whether an Alphabet is vowel or consonant in C++
Python code to check whether a character is vowel or consonant
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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago