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:
No comments:
Post a Comment
Let Us hear Your thoughts about this Post.. Its Our Pleasure to get your feedback..