Write a C program to check whether an alphabet is vowel or consonant using switch case
Question
Write a C program to check whether an alphabet is vowel or consonant using switch case
Solution
Sure! Here is a step-by-step guide to writing a C program to check whether an alphabet is a vowel or consonant using a switch case:
-
Start by including the necessary header file for input/output operations:
#include <stdio.h> -
Define the main function:
int main() { // code goes here return 0; } -
Declare a character variable to store the input alphabet:
char alphabet; -
Prompt the user to enter an alphabet:
printf("Enter an alphabet: "); -
Read the input alphabet from the user:
scanf("%c", &alphabet); -
Use a switch case to check whether the input alphabet is a vowel or consonant:
switch (alphabet) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'A': case 'E': case 'I': case 'O': case 'U': printf("%c is a vowel.\n", alphabet); break; default: printf("%c is a consonant.\n", alphabet); break; } -
Finally, end the program:
return 0;
Here's the complete program:
#include <stdio.h>
int main() {
char alphabet;
printf("Enter an alphabet: ");
scanf("%c", &alphabet);
switch (alphabet) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is a vowel.\n", alphabet);
break;
default:
printf("%c is a consonant.\n", alphabet);
break;
}
return 0;
}
This program will prompt the user to enter an alphabet and then determine whether it is a vowel or consonant using a switch case.
Similar Questions
Write a C program to read an English Alphabet through keyboard and display whetherthe given alphabet is in upper case or lower case.
letter countWrite a C program that will analyze a line of text and will print the number of words, the number of consonants, and the number of vowels in the text.Testcase:Input:Programming is fun!Output:3 // Number of words:11 // Number of consonants:5 // Number of vowels:
Write a program in C to count the number of vowels and consonants in a string. You can use fgets to read the characters.
Take character as input from the console using input() function. Write a program to check whether the given input is a vowel or a consonant or a letter are not. Print the result to the console as shown in the examples.Sample Input and Output 1:ch: Aletter and vowelSample Input and Output 2:ch: Pletter and consonantSample Input and Output 3:ch: @not letter
Write a program to check whether a given character is Alphabet or not using if else statement Note: Check for both upper and lower case characters
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.