Tuesday, 17 March 2015

Counting vowels,consonants,digits,special & words Using C

# include <stdio.h>
# include <conio.h>
# include <ctype.h>

void main()
{
char text[80], ch ;
int vowel = 0, cons = 0, digit = 0, word = 0, special = 0, i = 0;
clrscr() ;
printf("Enter the text : ") ;
gets(text) ;
while((ch = tolower(text[i++])) != '\0')
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
++vowel ;
else if(ch >= 'a' && ch <= 'z')
++cons ;
else if(ch >= '0' && ch <= '9')
++digit ;
else if(ch == ' ')
++word ;
else
++special ;
}
++ word ;
printf("\nThe text contains : ") ;
printf("\n\nNumber of vowels = %d", vowel) ;
printf("\n\nNumber of consonants = %d", cons) ;
printf("\n\nNumber of digits = %d", digit) ;
printf("\n\nNumber of special characters = %d", special) ;
printf("\n\nNumber of words = %d", word) ;
getch() ;
}

RUN 1 :
~~~~~~~
Enter the text : Bhuvan was born in 2nd Nov 1977 !!!
The text contains :
Number of vowels = 6
Number of consonants = 14
Number of digits = 5
Number of special characters = 3
Number of words = 8

No comments:

Post a Comment