Ads Top

NUMBER OF WORDS IN A SENTENCE PROGRAM USING CPP

#include<conio.h>
#include<iostream.h>
#include<stdio.h>
void main()
{
clrscr();

char text[80];
int c=0;
cout<<"enter the sentence \n" ;
gets(text);
for(int i=0;text[i]!='\0';i++)
{
 if(text[i]==' '&&text[i+1]!=' ')
 {

 c=c+1;
 }
}
 cout<<"the number of words "<<c+1;
 getch();
 }

OUTPUT:

Enter the sentence
C is a programming language
The number of words 5

No comments:

Touchfeeds. Powered by Blogger.