/*9. C program to count the number of vowels, consonants and special characters in a string.*/
#include <stdio.h>
void main()
{
char str[100];
int i, digit, vowel, consonant, splchar, spaces;
clrscr();
digit = vowel = consonant = splchar = spaces = 0;
printf("Enter a string: ");
gets(str);
for(i=0;str[i]!=NULL;i++)
{
if(str[i]>='0' && str[i]<='9')
digit++;
else if(str[i]==' ')
spaces++;
else if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]== 'O' || str[i]=='U' ||
str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u')
vowel++;
else if((str[i]>='A' && str[i]<='Z')||(str[i]>='a' && str[i]<='z'))
consonant++;
else
splchar++;
}
printf("\nDigits: %d \nVowels: %d \nSpaces: %d \nConsonants: %d \nSpecial Characters: %d",digit,vowel,spaces, consonant,splchar);
getch();
}
#include <stdio.h>
void main()
{
char str[100];
int i, digit, vowel, consonant, splchar, spaces;
clrscr();
digit = vowel = consonant = splchar = spaces = 0;
printf("Enter a string: ");
gets(str);
for(i=0;str[i]!=NULL;i++)
{
if(str[i]>='0' && str[i]<='9')
digit++;
else if(str[i]==' ')
spaces++;
else if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]== 'O' || str[i]=='U' ||
str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u')
vowel++;
else if((str[i]>='A' && str[i]<='Z')||(str[i]>='a' && str[i]<='z'))
consonant++;
else
splchar++;
}
printf("\nDigits: %d \nVowels: %d \nSpaces: %d \nConsonants: %d \nSpecial Characters: %d",digit,vowel,spaces, consonant,splchar);
getch();
}