➤ If-else Statement in C
➤ Programs on if-else
➤ Switch Case in C
➤ Switch case Programs
➤ Conditional Operator
➤ While loop in C
➤ Do-while loop in C
➤ While vs do-while
➤ For loop in C
➤ Break keyword in C
➤ Continue keyword in C
➤ Break vs Exit in C
➤ Goto keyword in C
☕️ Flow Control Programs
➤ Largest in 3 Numbers
➤ Find Grade of student
➤ Find the absolute value
➤ Vowel or Consonant
➤ Leap Year Program
➤ Simple calculator in C
➤ Check Odd or Even
➤ Roots of Quadratic Equation
➤ Find Reverse of Number
➤ Factors of a number in C
➤ Generate Multiplication table
➤ Find Power of a Number
➤ Find GCD and LCM
➤ Find factorial of Number
➤ Count Number of Digits
➤ Sum of digits in Number
➤ Sum of N Natural Numbers
➤ Sum of Squares of Natural No.
➤ Find Sum of Odd Numbers
➤ Find the Sum of Series
➤ Find Fibonacci series in C
➤ Sum of the Fibonacci series
➤ Sum until enters +ve numbers
➤ Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
➤ Celsius to Fahrenheit
➤ Fahrenheit to Celsius
➤ Decimal ↔ Binary
➤ Decimal ↔ Octal
➤ Octal ↔ Binary in C
☕️ Number Programs in C
➤ Prime Number in C
➤ Strong Number in C
➤ Krishnamurthy Number
➤ Neon Number in C
➤ Palindrome number
➤ Perfect Number in C
➤ Armstrong Number
☕️ Pattern Programs in C
➤ Pattern programs in C
➤ Printing pattern using loops
➤ Floyd’s triangle Program
➤ Pascal Triangle Program
➤ Pyramid Star Pattern in C
➤ Diamond Pattern Programs
➤ Half Diamond pattern in C
➤ Print Diamond Pattern
➤ Hollow Diamond Pattern
➤ Diamond Pattern of Numbers
In the English language, the letters A, E, I, O, U and a, e, i, o, u defined as a vowel. Except these all other letters are consonants. We can write a c program to check vowel or consonant using an if-else statement or by using switch-case statements.
Prerequisites for checking vowel or consonant:- If-else statement in C, Programs on if-else in C, Switch case in C programming, Programs on switch case in C
C program to check vowel or consonant Using If-else
#include<stdio.h>
int main()
{
char ch;
char uppercase, lowercase;
printf("Enter any character: ");
scanf("%c", &ch);
uppercase = (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U');
lowercase = (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
if( uppercase || lowercase )
printf("%c is Vowel.",ch);
else
printf("%c is consonant.",ch);
return 0;
}
Output:-
Enter any character: a
a is Vowel.
Enter any character: K
K is consonant.
In this program, we take two variables “uppercase” and “lowercase”. If the character is in uppercase and vowel then uppercase stores 1 else it store 0. Similarly, the variable lowercase store 1 if the character is in lowercase and vowel else it will store 0.
Now, inside if condition when at least one variable (among the variables uppercase and lowercase) value is 1 then condition will be true and the character is a vowel, else the character is consonant.
In the above program if the character is not alphabet i.e. special character or digits then it will display consonant. It is not the correct answer. When the character is not an alphabet then it should display different results. The given below program shows it.
Check Character is Vowel or Consonant using Switch case
#include<stdio.h>
int main()
{
char ch;
char uppercase, lowercase;
int result;
printf("Enter any character: ");
scanf("%c",&ch);
uppercase = (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U');
lowercase = (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
result = ( uppercase||lowercase );
switch(result)
{
case 1:
printf("Vowel\n");
break;
case 0:
printf("Consonant\n");
break;
default:
printf("Invalid character\n");
break;
}
return 0;
}
Output:-
Enter any character: e
Vowel
Enter any character: p
Consonant
In this program when the character is not an alphabet then the default statement is executed and displayed “Invalid character” to the screen.
With the help of pre-defined function
In the above two programs, we were taking uppercase and lowercase letter differently. By this way, we need to write some extra code. For this solution, we can use either tolower() or toupper() function which is defined in “ctype.h
“
tolwer(c)
:- It returns lowercase version if the c is a capital letter otherwise it returns c.
toupper(c)
:- It returns uppercase version if the c is a lowercase letter otherwise, it returns c.
When we use the tolower() function, we need to check only for lowercase letters, not for uppercase letters. Now, we can use either an if-else or switch-case statement.
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
int result;
printf("Enter any character: ");
scanf("%c",&ch);
ch = tolower(ch);
result = (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
switch(result)
{
case 1:
printf("Vowel\n");
break;
case 0:
printf("Consonant\n");
break;
default:
printf("Invalid character\n");
break;
}
return 0;
}
Output:-
Enter any character: S
Consonant
Enter any character: I
Vowel
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!