In: Computer Science
write a program in c language to count the number of
spaces ina sentence .the sentence is saved in the string
'sentence'
write it in a repl.it and along with input,output and
algorithm
Algorithm
step 1 Take user input.
step 2 save this input in a character array.
step 3 find the length of string.
step 4 use loop from first character to the last character of the
string and compare every character with space,and if character is
equal to space then increment a counter variable.
step 5. after loop print the value of counter variable.
// Code
#include<stdio.h>
#include<string.h>
int main()
{
char sentence[100];
int l,i;
int c=0;
printf("\n Enter a sentence :");
gets(sentence);
puts(sentence);
l=strlen(sentence);
for (i=0;i<l;i++)
{
if (sentence[i]==' ')
c++;
}
printf("\nNumber of spaces are %d",c);
}