Q:

C Program to Count Vowels, Consonants, Digits and Spaces in Given String

belongs to collection: String in C Programs

0
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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<stdio.h>

int main()
{

    printf("=====================================");
    printf("\nnerdutella.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:

==============================

nerdutella.com

==============================

Enter a Line of String :

ghanendra pratap singh yadav  student  of  Nit warangal Mobile No.is 7842xxxxxx

output Is Below

Total Number of Vowels Are:20

Total Number of Consonants:41

Total Number of Digits Are :4

Total Number of White space Are:11

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program For Reverse a String Using Pointers... >>
<< C Program to Compare Two Strings Using strcmp...