Consonants and so on - (C Programs)
In this tutorial, we'll discuss a C program that takes a character input from the user and identifies whether it is a vowel, consonant, or special character. We'll cover the syntax and example of this program.
Syntax
The syntax for identifying vowels, consonants, and special characters in C is as follows:
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
printf("%c is a vowel.", ch);
else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
printf("%c is a consonant.", ch);
else
printf("%c is a special character.", ch);
Where ch
is the character input by the user.
Example
Let's take an example to illustrate the program:
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
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("%c is a vowel.", ch);
else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
printf("%c is a consonant.", ch);
else
printf("%c is a special character.", ch);
return 0;
}
Output:
Enter a character: a
a is a vowel.
Explanation
In the above example, the user is asked to input a character. The program then checks if the input is a vowel or consonant or special character using if-else statements. For a vowel, the program prints is a vowel
, for a consonant it prints is a consonant
, and for a special character, it prints is a special character
.
Use
This program is useful when you want to check whether a character input is a vowel, consonant, or special character. It can be used in a variety of scenarios, such as data filtering or program input validation.
Summary
In this tutorial, we discussed a C program that identifies vowels, consonants, and special characters. We covered the syntax, example, explanation, use, and important points. By using this program, you can easily identify the type of character input by the user in your C program.