C program to find vowels and consonants in string || string manipulation in C || C programming

In this,we are going to see a program in which we can count the number of vowels and consonants in a string in C Programming Language. 

// Count number of constant & vowel in string

#include <stdio.h>

int main()
{
    char str[30];
    int vow = 0, cons = 0, i = 0;
    printf("enter a string:");
    gets(str);
    while (str[i] != '\0')
    {
        //condition to check vowel
        if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'O' || str[i] == 'U' || str[i] == 'I')
        {
            vow++;
        }

        //input value is consonant
        else
        {
            cons++;
        }
        i++;
    }
    printf("number of vowels=%d", vow);
    printf("number of constants=%d", cons);
    return 0;
}

//..........coded by ANANYA MAURYA

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post