1
2 PROGRAM no_of_words;
3
4 {Program to count the number of words in a sentence}
5
6 USES crt;
7
8 CONST space=' ';
9
10 VAR nextchar:char;
11 words:integer;
12
13 BEGIN
14 words:=1;
15 clrscr;
16 writeln('Input sentence-terminate with return');
17 WHILE not eoln DO
18 BEGIN
19 read(nextchar); {If readln was used instead of
20 read then the program would not work}
21 IF nextchar=space THEN
22 words:=words+1;
23 END;
24 writeln('Number of words in the sentence => ',words);
25 END.
26
27
28
29