program ackermann;
uses crt;
var
m, n, ack_result : integer;
function ack(x,y : LongInt): LongInt;
var
w, res : LongInt;
begin
if x = 0 then
begin
y := y+1;
res := y;
end
else if (x>0) and (y=0) then
begin
res := ack(x-1,1)
end
else if (x>0) and (y>0) then
begin
w := ack(x,y-1);
res := ack(x-1,w);
end;
ack := res;
end;
begin
clrscr;
writeln('===== | Ackermann Function | =====');
WriteLn('Please type m and n value to calculate ack(m, n)');
Write('m = ');readln(m);
Write('n = ');readln(n);
ack_result := ack(m,n);
WriteLn('Value of ack(', m,',',n,') is = ', ack_result);
ReadKey;
end.