Write a C program to find number of words in a given sentence.

Program:

#include<stdio.h>
#include<conio.h>

void main()
{
    char str[45];
    int count=0,i;
    clrscr();
    printf("Enter the Sentence: ");
    gets(str);
    for(i=0;str[i]!='\0';i++)
    {
    if(str[i]==' ')
        count++;
    }
    printf("\nThe given sentence has %d words",count+1);
    getch();
}


Sample Output:


Funny Program.. Have fun..! :)

Program:

#include<stdio.h>
#include<conio.h>

void main()
{
    int i=0;
    char a[40]="Hi..Your System Screen Become Mad :)",b='a';
    clrscr();
    printf("To stop the process,press: q\nElse Start typing!\n\n");
    while(b!='q')
    {
        b=getch();
        printf("%c",a[i]);
        i++;
        if(i==36)
        {
        i=0;
        printf("\n");
        }
    }
}


Sample Output:


Programs and Solutions