Computer Science, asked by anupamdude123, 1 year ago

WAP to input a sentence then count total number of words in the sentence

Answers

Answered by siddhartharao77
2
#include<iostream>

 int main( )

 {

char a[200];

cout<< "Enter a sentence: ";

cin.getline(a,200);

int b = 0;

for(int i = 0; a[i] != '\0'; i++)

{

if (a[i] == ' ')

{

   b++;

}

}

cout<< "The number of words are = "<< b+1 << endl;

return 0;

}
Similar questions