Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE petak;
- FROM InOut IMPORT WriteString, WriteLn, WriteInt, ReadInt;
- CONST maxR=20;
- maxN=30;
- TYPE niz=ARRAY [0..maxN] OF INTEGER;
- PROCEDURE grec(n,r: INTEGER): INTEGER; FORWARD;
- PROCEDURE frec(n,r:INTEGER):INTEGER;
- BEGIN
- IF n<r THEN
- RETURN 2
- ELSE
- IF ODD(n) THEN
- RETURN frec(n-2,r)-grec(n-1,r)+frec(n-r+1,r)-grec(n-r,r)
- ELSE
- RETURN -frec(n-1,r)+grec(n-1,r)-grec(n-2,r)-frec(n-r,r)+grec(n-r,r);
- END;
- END;
- END frec;
- PROCEDURE grec(n,r:INTEGER):INTEGER;
- BEGIN
- IF n<r THEN
- RETURN -1
- ELSE
- RETURN 2*grec(n-1,r)-2*frec(n-r,r)+grec(n-r+1,r)
- END;
- END grec;
- PROCEDURE frec2(n,r: INTEGER): INTEGER;
- PROCEDURE F(f,g: niz; i:INTEGER): INTEGER;
- VAR j: INTEGER;
- BEGIN
- IF i>n THEN
- RETURN f[r]
- ELSE
- IF ODD(i) THEN
- f[r]:=f[r-2]-g[r-1]+f[1]-g[0];
- ELSE
- f[r]:=-f[r-1]+g[r-1]-g[r-2]-f[0]+g[0];
- END;
- g[r]:=2*g[r-1]-2*f[0]+g[1];
- FOR j:=0 TO r-1 DO
- f[j]:=f[j+1];
- g[j]:=g[j+1];
- END;
- RETURN F(f,g,i+1);
- END;
- END F;
- VAR f,g:niz;
- j: INTEGER;
- BEGIN
- IF n<r THEN
- RETURN 2
- ELSE
- FOR j:=0 TO r-1 DO
- f[j]:=2;
- g[j]:=-1;
- END;
- RETURN F(f,g,r);
- END;
- END frec2;
- PROCEDURE fiter(n,r: INTEGER):INTEGER;
- VAR f,g:niz;
- i,j: INTEGER;
- BEGIN
- FOR i:=0 TO r-1 DO
- f[i]:=2;
- g[i]:=-1;
- END;
- IF n<r THEN
- RETURN f[n]
- ELSE
- FOR i:=r TO n DO
- IF ODD(i) THEN
- f[r]:=f[r-2]-g[r-1]+f[1]-g[0];
- ELSE
- f[r]:=-f[r-1]+g[r-1]-g[r-2]-f[0]+g[0];
- END;
- g[r]:=2*g[r-1]-2*f[0]+g[1];
- FOR j:=0 TO r-1 DO
- f[j]:=f[j+1];
- g[j]:=g[j+1];
- END;
- END;
- RETURN f[r];
- END;
- END fiter;
- VAR n,r: INTEGER;
- BEGIN
- REPEAT
- WriteString('Unesite n (0<=n<= ');
- WriteInt(maxN,1);
- WriteString('): ');
- ReadInt(n);
- WriteLn;
- UNTIL (0<=n) AND (n<=maxN);
- REPEAT
- WriteString('Unesite r (5<=r<= ');
- WriteInt(maxR,1);
- WriteString('): ');
- ReadInt(r);
- WriteLn;
- UNTIL (0<=r) AND (r<=maxR);
- WriteString('frec1(n,r) = ');
- WriteInt(frec(n,r),0);
- WriteLn;
- WriteString('frec2(n,r) = ');
- WriteInt(frec2(n,r),0);
- WriteLn;
- WriteString('fiter(n,r) = ');
- WriteInt(fiter(n,r),0);
- WriteLn;
- END petak.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement