Alphabets

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

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

Code to check Vowel  or consonant

Code to check the 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 consonant using if-else and || operator in C language

Program 1

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

int main()
{
    char ch;
//Declare character variable
    printf("Enter an Alphabet\n");
    //Ask input from the user
    scanf("%c",&ch);//Store the entered character in ch variable

          //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 a vowel",ch);//Display vowels
}
else{
  printf("%c  is a consonant",ch);//display consonant

}
getch();
    return 0;

}

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

Case 1

Enter an Alphabet
M
M is a consonant

Case 2

Enter an Alphabet
u
u is a Vowel

 

Code to check the Alphabet is Vowel or consonant using Nested If else

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 statements

Program 2

#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 a vowel",ch);
}
else{//display consonant
printf("%c is a consonant",ch);
}

}
else{
printf("%c is neither a vowel nor a consonant",ch);
}

getch();
    return 0;
}

 

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

Case 1

Enter an Alphabet
e
e is a Vowel

Case 2

Enter an Alphabet
Y
Y is a consonant

Code to check the Alphabet is Vowel or consonant using Ascii

In this code, we are going to learn how to write a program to check  the given  English alphabet is Vowel or consonant using Ascii value

Program 3

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

int main()
{
    char ch;
//Declare character variable
    printf("Enter a Alphabet\n");
    //Ask input from the user
    scanf("%c",&ch);//Store the entered character in ch variable

          //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)
{
  printf("%c is vowel",ch);//Display vowels
}
else{
  printf("%c  is  consonant",ch);//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
m
m is a consonant

 

Code to check the Alphabet is Vowel or consonant using switch

In this code, we are going to learn how to write a program to check  the given  English alphabet is Vowel or consonant using Switch case statements in C language

Program 4

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

int main()
{
    char ch;
    printf("Enter any Alpabet\n"); //input alphabet from user
    scanf("%c",&ch);//store the Entered Alphabet in ch

    switch(ch){
  //check lower case vowel letters
  case 'a':
  printf("%c is a vowel",ch);
  break;

  case 'e':
  printf("%c is a vowel",ch);
  break;

  case 'i':
  printf("%c is a vowel",ch);
  break;

  case 'o':
  printf("%c is a vowel",ch);
  break;

  case 'u':
  printf("%c is a vowel",ch);
  break;

  //check upper case vowel letters
  case 'A':
  printf("%c is a vowel",ch);
  break;

  case 'E':
  printf("%c is a vowel",ch);
  break;

  case 'I':
  printf("%c is a vowel",ch);
  break;

  case 'O':
  printf("%c is a vowel",ch);
  break;

  case 'U':
  printf("%c is a vowel",ch);
  break;

  default:
  printf("%c is a consonant",ch);
  break;
    }
    getch();

    return 0;
    }

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

Case 1

Enter an Alphabet
e
e is a Vowel

Case 2

Enter an Alphabet
n
n is a consonant

 

Suggested post

if else in C language

Nested if in C language

Operator 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

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.