This is a C program that takes a sentence as input from the user and counts the number of vowels, consonants, capital letters, small letters, and special characters in the sentence.
The program declares 5 variables, small, cap, vowel, cons, and spl, to store the count of each category of characters. The function gets is used to read the input sentence from the user and store it in an array of characters named a.
The for loop iterates over the elements of the a array until it encounters a null character ('\0'), which marks the end of the string. The code inside the loop checks the ASCII value of each character in the string and increments the appropriate counter based on the following conditions:
#include<stdio.h> int main() { int i,small=0,cap=0,vowel=0,cons=0,spl=0; char a[100]; printf("\nEnter the Sentence:"); gets(a); for(i=0;a[i]!='\0';i++) { if(a[i]>=97&&a[i]<=122) { small++; if(a[i]==97||a[i]==101||a[i]==105||a[i]==111||a[i]==117) { vowel++; } else { cons++; } } else if(a[i]>=65&&a[i]<=90) { cap++; if(a[i]==65||a[i]==69||a[i]==73||a[i]==79||a[i]==85) { vowel++; } else { cons++; } } else { spl++; } } printf("\nVowels:%d",vowel); printf("\nConsonents:%d",cons); printf("\nCapital letters:%d",cap); printf("\nSmall letters:%d",small); printf("\nSpecial characters:%d",spl); return 0; }To download raw file Click Here
Enter the Sentence: Tutor Joe's Computer Education is the best education center Tutor Joe's Computer Education is the best education center Vowels:22 Consonents:28 Capital letters:4 Small letters:46 Special characters:9
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions