Monday, 31 October 2011

Program to count vowels consonents and spaces in a string




#include<stdio.h>
main()
{
int i,cons=0,vow=0,sp=0;
char a[100];
printf("Enter the sentence\n");
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='a'||a[i]=='A')
vow=vow+1;
else if(a[i]=='e'||a[i]=='E')
vow=vow+1;
else if(a[i]=='i'||a[i]=='I')
vow=vow+1;
else if(a[i]=='o'||a[i]=='O')
vow=vow+1;
else if(a[i]=='u'||a[i]=='U')
vow=vow+1;
else if(a[i]==' ')
sp=sp+1;
else
cons=cons+1;
}
printf("Total number of vowels entered = %d\n",vow);
printf("Total number of consonents entered = %d\n",cons);
printf("Total number of spaces entered = %d\n",sp);
}

No comments:

Post a Comment