C Program for Counting the Number of Vowel, Consonant, Digit, Word, Other From a String

In this C program, We will show “How to Counting the Number of Vowel, Consonant, Digit, Word, Other From a String ” . So, let’s do it …

#include<stdio.h>
int main()
{
    char str[100], ch;
    int i, vowel, consonant, digit, word, other;

    printf("Enter a String: ");
    fgets(str, 100, stdin );

    i=vowel=consonant=word=digit=other=0;

    while((ch=str[i]) != '\n')
    {
        if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'
            || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
                vowel++;

        else if((ch >= 'a' && ch <= 'z' ) || (ch >= 'A' && ch <= 'Z' ))
            consonant++;

        else if(ch >= 0 && ch <= 9)
            digit++;

        else if(ch == ' ')
            word++;

        else
            other++;

         i++;
    }
    word++;

    printf("Number of Vowel = %d\n",vowel);
    printf("Number of Consonat = %d\n",consonant);
    printf("Number of Digit = %d\n",digit);
    printf("Number of Word = %d\n",word);
    printf("Number of Other = %d\n",other);

    getchar();

return 0;
}

Keep Learning with PrologiCode.

Leave a Comment