My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to count vovels,digits,spaces,consonent and other characters in a string

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
 char str[100];
 int vov=0,con=0,d=0,sp=0,oth=0;
 clrscr();
 cout<<"enter the string:"<<endl;
 cin.get(str,100);
 for(int i=0;str[i]!='\0';i++)
  {
  if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
  vov++;
  else if(str[i]>'a'&&str[i]<='z')
  con++;
  else if(str[i]>='0'&&str[i]<='9')
  d++;
  else if(str[i]==' ')
  sp++;
  else
  oth++;
  }
  cout<<"number of vovels "<<vov<<endl;
  cout<<"number of consonents "<<con<<endl;
  cout<<"number of digits "<<d<<endl;
  cout<<"number of spaces "<<sp<<endl;
  cout<<"number of other characters "<<oth<<endl;
  getch();
  }

0 comments: