Program to find the Number of Vowels, Consonants, Digits and White Space in a String

Table of Contents

PROGRAM:

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
    char line[150];
    int i,v,c,ch,d,s,o; o=v=c=ch=d=s=0;
    cout << "Enter a line of string: " << endl;
    cin.getline(line, 150);
    for(i=0;line[i]!='';++i)
    {
        if(line[i]=='a'
        || line[i]=='e'
        || line[i]=='i'
        || line[i]=='o'
        || line[i]=='u'
        || line[i]=='A'
        || line[i]=='E'
        || line[i]=='I'
        || line[i]=='O'
        || line[i]=='U')
            ++v;
        else if((line[i]>='a'&& line[i]<='z')
               || (line[i]>='A'&& line[i]<='Z'))
                ++c;
        else if(line[i]>='0'&&c<='9')
                ++d;
        else if (line[i]==' ')
                ++s;
    }
    cout << " Vowels: " << v << endl;
    cout << " Consonants: " << c << endl;
    cout << " Digits: " << d << endl;
    cout << " White Spaces: " << d << endl;
    return 0;
}

 

OUTPUT:

find number of vowels consonants digits and white space in a string

Leave a Comment