"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, March 4, 2010

WAP to enter a string. Print it in reverse. Also print the number of vowels, consonants, blank spaces.


#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>

void main()
{
char str[100];
int vowel = 0, cons = 0, sp = 0, chr = 0;

for(int i = 0; str[i] != '\0' ; i++)
{

/* count vowels */
if(toupper(str[i])=='A' || toupper(str[i]) == 'E' || toupper(str[i]) == 'I' || toupper(str[i] == 'O' || toupper(str[i]) == 'U' ))
     vowel++;

else
{
/* count spaces */
    if(str[i] == ' ')
        sp++;
    else
       {
/* count comma or stop as other character */
          if(str[i] == '.' || str[i] == ',')
              chr++;
          else
               cons++;
        }
}
}

cout<< "\n The original string = " << str;

cout<< "\n The total number of vowels = " << vowel;
cout<< "\n The total number of consonants = " << cons;
cout<< "\n The total number of balnk spaces = " << sp;
cout<< "\n The total number of other characters like comma or full-stops =" << chr;

int l = strlen(str);

cout<< "\n The string in reverse is ";
for(i=l-1; i>=0 ; i--)
cout<< str[i];

getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.