9.4.20

finding number of words in a sentence example 2


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

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...