Friday, November 23, 2012

WRITE A C PROGRAM TO COUNT THE NUMBER OF WORDS IN A SENTENCE.



/*    WRITE A C PROGRAM TO COUNT THE NUMBER OF WORDS IN A 
     SENTENCE.
*/
#include<stdio.h>
#include<conio.h>

#define MAX 100

void main()
{
            char str[MAX];
            int words=0,i;
            clrscr();

            printf("Enter a sentence : ");
            gets(str);

            for(i=0;str[i]!='\0';i++)
                        if(str[i]==' ')
                                    words++;

            printf("The number of words in the sentence is %d",words+1);
            getch();
}

/*

            =====OUT PUT=====

            Enter a sentence : BHARATH KAUNDUNYA SRIKANTH ARE GOOD FRIENDS.
            The number of words in the sentence is 6

*/






0 comments:

Post a Comment