(C++) CPP Programs - 23

Friday, December 14, 2007

23. Write a C program to read a sentence and count the number of vowels and consonants in the given sentence. Output the results on two lines with suitable headings.

/* vowels and consonants*/

#include
#include
#include
#include

void main()
{
char str[50];
int i,n,vow=0,con=0;

clrscr();
printf("\nEnter an string\n");
gets(str);

printf("\nThe given string is\n");
puts(str);

n=strlen(str);

for(i=0;i < n;i++)
{
if(isalpha(str[i]))
switch(tolower(str[i]))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': vow++;
break;

default: con++;
}
}
printf("\nThe number of vowels=%d\n",vow);
printf("\nThe number of consonants=%d\n",con);

getch();
}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP