In this post we are going to make the program in c to count the vowels in String, String is given by the user. When the user input any string this program finds the first letter and gives the output, in this program, we use the switch function.
Algorithm:-
Step 1:- Start
Step 2:- Take input of a string.
Step 3:- Check if the string’s 1st letter is a vowel.
Step 4:- Print whether it is a vowel or not.
Step 5:- Stop
Rules
1. We write Header File.
2. Declare Vowels as Characters.
3. Take input from the User.
4. Use the Switch Function
5. Write all Vowels in Switch
6. Print the first letter as Vowel or Not.
Code
#include<stdio>
int main()
{
char vowels;
printf("Enter a character\n");
scanf("%c", &vowels);
switch(vowels)
{
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", vowels);
break;
default:
printf("%c is not a vowel.\n", vowels);
}
return 0;
}
Output
Enter a character
anmol
a is a vowel.