Q: How to find the vowels count of a given text by using switch in C program?
This C program is used to find the number of vowels in your given text by using a switch statement. Initially checking the character of text separately and match with case value. If the character matches with the condition, then increment by one in the vowel count or ignore the character. Finally print the number of vowels present in the given input text.
Vowels count program in C:
//Header files
#include<stdio.h>
#include<conio.h>
void main()
{
//Program varaibles
int eCou=0,aCou=0,oCou=0,iCou=0,conCou=0,uCou=0;
char cha;
clrscr(); //Function to clear the previous output
printf("Enter ur text here : \n"); //Display function
while((cha=getchar())!='\n') //Unconditional statement
{
switch(cha) //Switch statement
{
case 'a':
aCou++; break;
case 'e':
eCou++; break;
case 'i':
iCou++; break;
case 'o':
oCou++; break;
case 'u':
uCou++; break;
default:
conCou++;
}
}
printf("Number of Character \n");
printf("a\t%d;e\t%d;i\t%d;o\t%d;u\t%d;rest\t%d ;",aCou,eCou,iCou,oCou,uCou,conCou);
getch();
}
[Read: Software Company List] & [Aptitude online portal]
C PROGRAM 2:
Q: How to find vowel count in a string by using unconditional statement and conditional statements?
//Header file section
#include
#include
//Global varaibles
int vowels(char []);
int c_vowel(char);
main()
{
// Program variables
char b[100];
int c;
printf("Enter the text\n"); //Display function
gets(b);
c = count_vowels(b); //Assigning value
printf("no of vowels: %d\n", c);
return 0;
}
int vowels(char f[])
{
int count = 0, g = 0, flag;
char a;
do//Unconditional statement
{
a = f[g];
flag = check_vowel(d);
if ( flag == 1 )
count++;
c++;
}while( a != '\0' );
return count;
}
int check_vowel(char f)
{
if ( f >= 'A' && f<= 'Z' ) //Conditional statement
f = a + 'a' - 'A'; //Lower case to upper case
if ( f == 'a' || f == 'e' || f == 'i' || f == 'o' || f == 'u')
return 1;
return 0;
}