// Write a program to count the number of vowels and consonants in a string
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char s[100];
int l,i,cons=0,vow=0;
clrscr();
cout<<"Enter the string: ";
cin.getline(s,100);
l=strlen(s);
for(i=0;i<l;i++)
if(isalpha(s[i]))
switch(toupper(s[i]))
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': vow++;
break;
default: cons++;
}
cout<<"Number of vowels:
"<<vow<<endl;
cout<<"Number of consonants:
"<<cons<<endl;
getch();
}

No comments: