program Code: program longestWord; var str, word, longestWord:string; i:integer; begin writeln('Enter a sentence: '); readln(str); str:=str+' '; word:=''; longestWord:='';
for i:=1 to length(str) do begin if (str[i]<>' ') then word:=word+str[i] else begin if (length(word)>length(longestWord)) then longestWord:=word; word:=''; end; end;
writeln('The longest word in the sentence is: ', longestWord); end.
program
Code:
program longestWord;
var
str, word, longestWord:string;
i:integer;
begin
writeln('Enter a sentence: ');
readln(str);
str:=str+' ';
word:='';
longestWord:='';
for i:=1 to length(str) do
begin
if (str[i]<>' ') then
word:=word+str[i]
else
begin
if (length(word)>length(longestWord)) then
longestWord:=word;
word:='';
end;
end;
writeln('The longest word in the sentence is: ', longestWord);
end.