Count Vowel and Consonant in C program

#include <stdio.h>
main()
{
char text[80];
int i, vowels = 0, consonants = 0, special = 0;

printf("Enter a text \n");
gets(text);
for (i = 0; text[i] != ‘\0’; i++)
{
if ((text[i] == ‘a’ || text[i] == ‘e’ || text[i] ==
‘i’ || text[i] == ‘o’ || text[i] == ‘u’) ||
(text[i] == ‘A’ || text[i] == ‘E’ || text[i] ==
‘I’ || text[i] == ‘O’ || text[i] == ‘U’))
{
vowels = vowels + 1;
}
else
{
consonants = consonants + 1;
}
if (text[i] ==’t’ ||text[i] ==’\0′ || text[i] ==’ ‘)
{
special = special + 1;
}
}
consonants = consonants – special;
printf("No. of vowels in %s = %d\n", text, vowels);
printf("No. of consonants in %s = %d\n", text, consonants);
}



Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image