C++ Program to count the number of words within an entered string and also print the string in reverse
#include<iostream.h>
#include<conio.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{ clrscr();
int s=0;
char a[25];
cout<<"enter a string";
gets(a);
int l=strlen(a);
for(int i=l;i>=0;i--)
{
cout<<a[i];
}
for(int j=0;j<l;j++)
{if(a[j]==' ')
{s=s+1; }
}
cout<<"number of words"<<s+1;
getch();
}







0 comments:
Post a Comment