Ask a Teacher



Write a C++ program input a number and find the number of vowels(the alphabets a,e,i,o,u)in it.

int main()
{   
    char x[10];
    int n,i,s=0;
    cout<<"Enter any string\n";
    cin>>x;
    n=strlen(x);
    for(i=0;i<n;++i)
    {
        if(x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u')
        {
            s=s+1;
       }
    }
    cout<<s;
    return 0;
}



Output of the program is as:

Enter any string 
elephant 
3


comments powered by Disqus