program WordCount;
vartext: string;count, i: integer;
beginwriteln('Enter a text: ');readln(text);
count := 0;i := 1;
while i <= length(text) dobeginif text[i] <> ' ' thenbegincount := count + 1;while (i <= length(text)) and (text[i] <> ' ') doi := i + 1;endelsei := i + 1;end;
writeln('Number of words in the text: ', count);end.
program WordCount;
var
text: string;
count, i: integer;
begin
writeln('Enter a text: ');
readln(text);
count := 0;
i := 1;
while i <= length(text) do
begin
if text[i] <> ' ' then
begin
count := count + 1;
while (i <= length(text)) and (text[i] <> ' ') do
i := i + 1;
end
else
i := i + 1;
end;
writeln('Number of words in the text: ', count);
end.