FINDING NUMBER OF WORDS IN A SENTENCE EXAMPLE 2
#include <stdio.h>
void main()
{
char st[128];
int i,nwords=0;
puts("enter a
sentence:");
gets(st);
for(i=0;st[i]!=0;i++)
if(st[i]==' '
&& st[i+1]!=' ')
nwords++;
printf("number of words=%d",nwords+1);
}
Output:
Enter a sentence
Incredible india
Number of words =2
No comments:
Post a Comment