Write a program to count number of vowel and consonant in string

Given a string we have to count the number of vowel and consonant present in a string.

so what is vowel and consonant?

vowel consist of 5 letter a,e,i,o,u. and other 21 letter of english alphabet are consonant. so we just need to find that only.


output:vowel:2 consonant :3

output:vowel:4 consonant:2


Step1:find the count  of vowel in a string 
step2: then to find consonant subtract the length of string with vowel count;
step 3:consonant=string length-vowel count;
# include <bits/stdc++.h> 
using namespace std; 
int isvowel(string s)
    int count=0;
    for(int i=0;i<s.length();i++)
    return count;
int main() 
cout<<"Enter string"<<endl;
string s;
int length=s.length();
int vowel_count=isvowel(s);
int consonant=length-vowel_count;
cout<<"vowel: "<<vowel_count<<" "<<"consonant: "<<consonant<<endl;

enter string:AADASFS
vowel: 3 consonant: 4

Time Complexity:O(N)

space Complexity:O(N)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top