Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE Binomni_koef1;
- FROM InOut IMPORT WriteString, WriteLn, WriteInt, ReadInt, WriteCard;
- CONST
- granica = 20;
- VAR
- n, k, rezultat : INTEGER;
- ok : BOOLEAN;
- PROCEDURE F(stari, n, k: INTEGER; VAR ok: BOOLEAN): INTEGER;
- BEGIN
- ok := MAX(INTEGER) DIV (n-k+1) >= stari;
- IF ok THEN
- RETURN stari * (n-k+1) DIV k
- ELSE
- RETURN stari
- END;
- END F;
- PROCEDURE BINk(n,k: INTEGER; VAR ok: BOOLEAN): INTEGER;
- VAR
- i, rezultat : INTEGER;
- BEGIN
- ok := TRUE;
- IF (0 < n) AND (n <= granica) AND (k >= 0) THEN
- IF k > n THEN
- RETURN 0
- ELSE
- IF k > n -k THEN
- k := n - k
- END;
- rezultat := 1;
- i := 1;
- WHILE (i <= k) AND ok DO
- rezultat := F(rezultat, n, i, ok);
- i := i +1
- END;
- RETURN rezultat
- END
- ELSE
- ok := FALSE
- END;
- RETURN 0
- END BINk;
- BEGIN
- WriteString('Unesite prirodan broj n, 0 <= n <=');
- WriteCard(granica,0);
- WriteLn;
- ReadInt(n);
- WriteLn;
- WriteString('Unesite prirodan broj k >= 0');
- ReadInt(k);
- WriteLn;
- rezultat := BINk(n,k,ok);
- IF ok THEN
- WriteLn;
- WriteString('Rezultat: ');
- WriteInt(rezultat,0)
- ELSE
- WriteString('Greska! ')
- END;
- END Binomni_koef1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement