Q : Write a program to calculate number of vowels (a,e,i,o,u) separately in an entered string.?
Solution :
#include<stdio.h>
void main()
{
int a,e,i,o,u,index;
char str[50];
a=e=i=o=u=0;
printf("Enter string>>
");
gets(str);
for(index=0;str[index]!='\0';index++)
{
switch(str[index
])
{
case 'a':
case 'A':
a++;
break;
case 'e':
case 'E':
e++;
break;
case 'i':
case 'I':
i++;
break;
case 'o':
case 'O':
o++;
break;
case 'u':
case 'U':
u++;
break;
}
}
printf("\nA=%d\ne=%d\nI=%d\nO=%d\nU=%d",a,e,i,o,u);
No comments:
Post a Comment