C program to check vowel or consonant; Through this tutorial, we will learn how to check whether an alphabet is vowel or consonant using function, ascii value and if else in c program.
Programs to Check Vowel or Consonant in C
- C program to check whether an alphabet is vowel or consonant using if else
- C Program to find Vowel or Consonant using Functions
- C Program to Check Vowel or Consonant using ASCII Values
C program to check whether an alphabet is vowel or consonant using if else
// C Program to Check Vowel or Consonant
#include <stdio.h>
int main()
{
char ch;
printf("Please Enter an alphabet: ");
scanf(" %c", &ch);
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
printf("\n %c is a VOWEL.", ch);
}
else {
printf("\n %c is a CONSONANT.", ch);
}
return 0;
}
The output of the above c program; as follows:
Please Enter an alphabet: i i is a VOWEL.
C Program to find Vowel or Consonant using Functions
// C Program to Check Whether an Alphabet is Vowel or Consonant
#include <stdio.h>
int check_vowel(char a);
int main()
{
char ch;
printf("Please Enter an alphabet: ");
scanf(" %c", &ch);
if(check_vowel(ch)) {
printf("\n %c is a VOWEL.", ch);
}
else {
printf("\n %c is a CONSONANT.", ch);
}
return 0;
}
int check_vowel(char c)
{
if (c >= 'A' && c <= 'Z')
c = c + 32;
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
return 1;
return 0;
}
The output of the above c program; as follows:
Please Enter an alphabet: g g is a CONSONANT.
C Program to Check Vowel or Consonant using ASCII Values
// C Program to Check Whether it is Vowel or Consonant
#include <stdio.h>
int main()
{
char ch;
printf("Please Enter an alphabet: ");
scanf(" %c", &ch);
if(ch == 97 || ch == 101 || ch == 105 || ch == 111 || ch == 117 ||
ch == 65 || ch == 69 || ch == 73 || ch == 79 || ch == 85)
{
printf("%c is a VOWEL.\n", ch);
}
else if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
{
printf("%c is a CONSONANT.\n", ch);
}
return 0;
}
The output of the above c program; as follows:
Please Enter an alphabet: a a is a VOWEL.