Problem:- C program to count the number of vowels, consonants and so on or C Program to Count Vowels, Consonants, Digits and Spaces in Given String or Find Number of Vowels, Consonants, Digits and White Space Characters or C Programming Notes: Counting vowels, consonants, digits, special character or C Program to Count words, vowels, letters, digits, spaces, Characters or Program to Find the Number of Vowels, Consonants, Digits and Whitespace in a String in C or Count the number of vowels, consonants, digits etc or C program to Count Vowels, Consonants, Digits, Spaces from String.
Explanation:- for Counting the vowels, constant, digits and white space in c is very simple we have to just put an if else condition for each query. As we can see that there are 4 query(vowels, constant, digits and white space) so we have 4 counter separate for each of them and for finding the vowels in a string or sentence if simple just put the 5 character in lower and upper case and compare with the input string if any character matches then increase the vowels counter and same for constant and digit, for a single iteration of a string any one of the counters should be increased. last counter for white space, and at the end print the all 4 counters values, total counter values is equal to the size of the string.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.
Solution:-
#include<stdio.h>
int main()
{
/*Visit - www.programmingwithbasics.com*/
printf("=====================================");
printf("\nVisit - www.programmingwithbasics.com");
printf("\n=====================================");
char line[1000];
int i, v, c, ch, d, s, o;
o = v = c = ch = d = s = 0;
printf("\n\nEnter a Line of String: \n\n");
gets(line);
for(i=0;line[i]!='\0';++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')
++v;
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
++c;
else if(line[i]>='0'&&c<='9')
++d;
else if (line[i]==' ')
++s;
}
printf("\n\nOutput Is Below\n\n");
printf("\n\nTotal Number of Vowels Are: %d",v);
printf("\nTotal Number of Consonants Are: %d",c);
printf("\nTotal Number of Digits Are: %d",d);
printf("\nTotal Number of White spaces Are: %d\n\n",s);
return 0;
}
Output:-
You May Also See
1. C Program For Remove All Vowels From A String
Welcome Bro To My Programming World I Hope You Will Enjoy Here
ReplyDelete