+3 votes
in Class 12 by kratos

Write a program to count the number of vowels and consonants in a string.

1 Answer

+6 votes
by kratos
 
Best answer

include<iostream.h>

include<string.h>

include<ctype.h>

void main()

{

char str[50];

int length,i,conso = 0,vowels = 0;

cout <<"Enter the text";

cin.getline(str,50);

length = strlen(str);

for(i = 0;i<length;i++)

if(isalpha(str[i]))

switch(toupper(str[i]))

{

case 'A':

case 'E':

case 'I':

case 'O':

case 'U': vowels++;

break;

default: conso++;

}

cout<<"The number of vowel characters is"<<vowels<<endl;

cout<<"The number of consonant characters is"<<conso<<endl;

}

...