Wednesday, 23 April 2014

22. Write a program to count number of vowels, consonants and spaces in a given string.



#include<stdio.h>
#include<conio.h> main()
{
char str[100];
int vowel=0,consonate=0,space=0,count,i; clrscr();
printf("enter the string to be counted\n"); gets(str);
printf("string = %s",str);
count=strlen(str); for(i=0;i<count;i++)
{
switch(str[i]) { case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': vowel++; break; case '  ':space++; break; default :consonate++;
}
}
printf("\nThe number of vowels are %d",vowel); printf("\nThe number of spaces are %d",space); printf("\nThe number of consonants are %d",consonate); getch();
return 0;
}

1 comment:

  1. I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often. word counter

    ReplyDelete