vedzz
10-29-2009, 06:35 PM
i was given a programme to identify no. of consonants, vowels, numerals and special characters in a string which is entered by user. although i have done it but i am looking for a simpler way to this provided that header files i have to use are just iostream.h, conio.h and stdio.h please help me if you have beter than this
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
clrscr();
char a[100];
int counter,vowel=0,consonant,numeral;
cout<<"Enter a sentence:"<<endl;
gets(a);
for(counter=0,consonant=0,numeral=0;a[i]!='\0';i++)
{
if(a[counter]=='a' || a[counter]=='e' || a[counter]=='i' || a[counter]=='o' || a[counter]=='u')
vowel++;
else
{
if(int(a[counter])<=91 && int(a[counter])>=65)
consonent++;
if(int(a[counter])>=96 && int(a[counter])<=122)
consonent++;
if(int(a[counter])>=48 && int(a[counter])<=57)
numeral++;
}
}
cout<<"Number of vowels are : "<<vowel<<endl<<"Number of consonants are : "<<consonant<<endl<<"Number of special characters are : "<<counter-consonent-vowel-numeral<<endl<<"Numbers of numerals are : "<<numeral;
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
clrscr();
char a[100];
int counter,vowel=0,consonant,numeral;
cout<<"Enter a sentence:"<<endl;
gets(a);
for(counter=0,consonant=0,numeral=0;a[i]!='\0';i++)
{
if(a[counter]=='a' || a[counter]=='e' || a[counter]=='i' || a[counter]=='o' || a[counter]=='u')
vowel++;
else
{
if(int(a[counter])<=91 && int(a[counter])>=65)
consonent++;
if(int(a[counter])>=96 && int(a[counter])<=122)
consonent++;
if(int(a[counter])>=48 && int(a[counter])<=57)
numeral++;
}
}
cout<<"Number of vowels are : "<<vowel<<endl<<"Number of consonants are : "<<consonant<<endl<<"Number of special characters are : "<<counter-consonent-vowel-numeral<<endl<<"Numbers of numerals are : "<<numeral;
getch();
return 0;
}