uses crt var str lastWord string byte function getLastWord str string

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
uses crt;
var str,lastWord:string;
t,i:byte;
function getLastWord(str:string):string;
var i:integer;
begin
i:=length(str);
while str[i] <> ' ' do dec(i);
getLastWord:=copy(str,i+1,length(str));
end;
procedure recursive(n:integer);
begin
if (n > 0) then
begin
write(lastWord[n]);
recursive(n-1);
end;
end;
begin
clrscr;
write('Choose type of task: ');
readln(t);
writeln('Enter the string');
readln(str);
lastWord:=getLastWord(str);
case t of
1: recursive(length(lastWord));
2:
begin
for i:=length(lastWord) downto 1 do
write(lastWord[i]);
end
else writeln('wrong task');
end;
readkey;
end.