Counting vowels, consonants, digits, special & words
Program:
#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();
}
Output:
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
-
UpdatedDec 31, 2019
-
Views27,615
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order