Q32 Write a program in C to count total number of vowel or consonant in a string.

Admin

 

Write a program in C to count total number of vowel or consonant in a string.

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100
int main()
{
    char str[MAX_SIZE];
    int i, len, vowel, consonant;
    printf("Enter any string: ");
    gets(str);
    vowel = 0;
    consonant = 0;
    len = strlen(str);
    for(i=0; i<len; i++)
    {
        if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
        {
            if(str[i] =='a' || str[i]=='e' ||str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i] =='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U'  )
                vowel++;
            else
                consonant++;
        }
    }
    printf("Total number of vowel = %d\n",vowel);
    printf("Total number of consonant = %d\n", 
   consonant);
    return 0;
}

Output


Enter any string: Hello How are You
Total number of vowel = 7
Total number of consonant = 7

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.