Programming Examples
C program to calculate number of vowels separately in an entered string
Write a program to calculate number of vowels (a,e,i,o,u) separately in an entered string
Solution
#include <stdio.h>
int main()
{
char str[200];
int a,e,i,o,u,x;
a=e=i=o=u=0;
printf("Enter any String : ");
gets(str);
for(x=0;str[x]!='\0';x++)
{
switch(str[x])
{
case 'a':
a++;
break;
case 'e':
e++;
break;
case 'i':
i++;
break;
case 'o':
o++;
break;
case 'u':
u++;
break;
}
}
printf("\nNumber of vowels (a) : %d",a);
printf("\nNumber of vowels (e) : %d",e);
printf("\nNumber of vowels (i) : %d",i);
printf("\nNumber of vowels (o) : %d",o);
printf("\nNumber of vowels (u) : %d",u);
return 0;
}
Output
Enter any String : infomax computer academy
Number of vowels (a) : 3
Number of vowels (e) : 2
Number of vowels (i) : 1
Number of vowels (o) : 2
Number of vowels (u) : 1