Tuesday, January 24, 2012

Sample C Program To Accept A String & Display Number Of Vowels.

#include
#include
#include

char vowels(char *p);

void main()
{

char str[10];
clrscr();
printf(" \n \n Enter the string: \t ");
gets(str);
vowels(str);
getch();

}

char vowels(char *p)
{

int i,l,v=0;
l = strlen(p);
printf(" \n \n The number of vowels in the string is: \t ");

for(i = 0 ;i < l ; i++)
{
if ( p[i] == 'a' || p[i] == 'e' || p[i] == 'i' || p[i] == 'o' || p[i] == 'u' ||
p[i] == 'A' || p[i] == 'E' || p[i] == 'I' || p[i] == 'O' || p[i] == 'U' )
{
v++;
}
else
continue;
}

printf("%d",v);
return 1;

}

No comments:

Post a Comment