Source code:
//Write a C program to find number of blank space in a sentence
#include <stdio.h>
int main()
{
char s[1000], ch;
int i = 0, count=0; /*i is array index and count is to count blank */
printf("Enter your sentence:");
while(ch != '\n') /* terminates if user hit enter */
{
ch = getchar();
s[i] = ch;
i++;
}
s[i-1] = '\0'; /* inserting null character at end */
for(i = 0; s[i] != '\0'; ++i)
{
if (s[i] == ' ')
count += 1;
}
printf("No. of blank space = %d", count);
return 0;
}
Output:
No comments:
Post a Comment