Sunday 20 May 2012

Write a program to accept a line of text and count the number of vowels and consonant in it.


//program to accept a line of text and count the number of vowels and consonant in it
main()
{
char a[100];
int i,v=0,c=0;
clrscr();
printf("Enter a sentence \n");
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='a'||a[i]=='A'||a[i]=='e'||a[i]=='E'||a[i]=='I'||a[i]=='i'||a[i]=='O'||a[i]=='o'||a[i]=='U'||a[i]=='u')
  c++;
else if(a[i]=='\t',a[i]==' ')
continue;
else
v++;
}
printf("%d vowels and %d consonants are present in the sentence",c,v);
getch();
return 0;
}
Output
Enter a sentence
We are the students of BCA
8 vowels and 13 consonants are present in the sentence

No comments:

Post a Comment