PROGRAM:
#include <iostream.h>
#include <conio.h>
void main() {
clrscr();
int wrdcnt=1;
char ch;
cout<<"Program to count number of WORDS entered by the user: \n";
cout<<"Enter your sentence: \n";
while((ch=getche())!='\r')
{
if(ch==' ')
wrdcnt++;
}
cout<<"\ntotal words in above sentence: "<<wrdcnt;
getch();
}
No comments:
Post a Comment