Program in C and C++ to check a given character is vowel or consonant Using conditional operator.
C
CPP
#include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character:-"); ch=getchar(); ch=toupper(ch); if(ch>=65&&ch<=90) (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')?printf("%c is vowel.",ch):printf("%c is consonant.",ch); else printf("%c is not alphabet.",ch); return 0; }
#include<iostream> #include<ctype.h> using namespace std; int main() { char ch; cout<<"Enter a character:-"; ch=getchar(); ch=toupper(ch); if(ch>=65&&ch<=90) (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')?printf("%c is vowel.",ch):printf("%c is consonant.",ch); else printf("%c is not alphabet.",ch); return 0; }
Output:-
Related programs
- Program in C to check a given character is vowel or consonant Using switch case.
- Program in C to check a given character is vowel or consonant Using if else statement
- Program in C & C++ to count the number of vowels and consonants in a string Using switch case.
- Program in C & C++ to count the number of vowels and consonants in a string Using pointer
0 Comments