ackermann function pascal

Solutions on MaxInterview for ackermann function pascal by the best coders in the world

showing results for - "ackermann function pascal"
Serena
28 Aug 2017
1program ackermann;
2uses crt;
3var
4    m, n,  ack_result : integer;
5
6function ack(x,y : LongInt): LongInt;
7var
8    w, res : LongInt;
9begin
10    if x = 0 then
11        begin
12            y := y+1; 
13            res := y;
14        end
15    else if (x>0) and (y=0) then
16        begin
17            res := ack(x-1,1)
18        end
19    else if (x>0) and (y>0) then
20        begin
21        w := ack(x,y-1);
22        res := ack(x-1,w); 
23        end;
24    ack := res;
25end;
26
27begin
28    clrscr;
29    writeln('===== | Ackermann Function | =====');
30    WriteLn('Please type m and n value to calculate ack(m, n)');
31    Write('m = ');readln(m);
32    Write('n = ');readln(n);
33    ack_result := ack(m,n);
34    WriteLn('Value of ack(', m,',',n,') is = ', ack_result);
35    ReadKey;
36end.