From: Doni Pracner Date: Wed, 6 Nov 2013 12:24:40 +0000 (+0100) Subject: 06 - kod folder X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=9a07854bc6033f0117bbb59dfcf7f4a615789d8c;p=spa2-teorijske-vezbe.git 06 - kod folder --- diff --git a/05. NizDin/NIZDIN.MOD b/05. NizDin/NIZDIN.MOD deleted file mode 100644 index 6156e77..0000000 --- a/05. NizDin/NIZDIN.MOD +++ /dev/null @@ -1,65 +0,0 @@ -MODULE NizDin; - - FROM IO IMPORT - WrStr, RdInt, WrInt; - - CONST - MaxN = 1000; - - VAR - a, b: ARRAY [0 .. MaxN] OF INTEGER; - (* b[i] je suma elemenata u resenju za *) - (* deo niza 'a' do 'i'-tog elementa *) - n: INTEGER; - - PROCEDURE Unos; - VAR - i: CARDINAL; - BEGIN - WrStr('Unesite N: '); - n:= RdInt(); - FOR i:= 1 TO n DO - WrStr('A['); - WrInt(i, 1); - WrStr('] = '); - a[i]:= RdInt(); - END; - END Unos; - - PROCEDURE Resi; - VAR - i, j, Pom: CARDINAL; - BEGIN - b[0]:= 0; - IF a[1] > 0 THEN - b[1]:= a[1]; - ELSE - b[1]:= 0; - END; - FOR i:= 2 TO n DO - IF b[i - 2] + a[i] > b[i - 1] THEN - b[i]:= b[i - 2] + a[i]; - ELSE - b[i]:= b[i - 1]; - END - END; - END Resi; - - PROCEDURE Ispis(n: CARDINAL); - BEGIN - IF n > 0 THEN - IF b[n] = b[n - 1] THEN - Ispis(n - 1); - ELSE - Ispis(n - 2); - WrInt(a[n], 8); - END; - END; - END Ispis; - -BEGIN - Unos; - Resi; - WrStr('Podniz: '); - Ispis(n); -END NizDin. diff --git a/05. NizDin/kod/NIZDIN.MOD b/05. NizDin/kod/NIZDIN.MOD new file mode 100644 index 0000000..6156e77 --- /dev/null +++ b/05. NizDin/kod/NIZDIN.MOD @@ -0,0 +1,65 @@ +MODULE NizDin; + + FROM IO IMPORT + WrStr, RdInt, WrInt; + + CONST + MaxN = 1000; + + VAR + a, b: ARRAY [0 .. MaxN] OF INTEGER; + (* b[i] je suma elemenata u resenju za *) + (* deo niza 'a' do 'i'-tog elementa *) + n: INTEGER; + + PROCEDURE Unos; + VAR + i: CARDINAL; + BEGIN + WrStr('Unesite N: '); + n:= RdInt(); + FOR i:= 1 TO n DO + WrStr('A['); + WrInt(i, 1); + WrStr('] = '); + a[i]:= RdInt(); + END; + END Unos; + + PROCEDURE Resi; + VAR + i, j, Pom: CARDINAL; + BEGIN + b[0]:= 0; + IF a[1] > 0 THEN + b[1]:= a[1]; + ELSE + b[1]:= 0; + END; + FOR i:= 2 TO n DO + IF b[i - 2] + a[i] > b[i - 1] THEN + b[i]:= b[i - 2] + a[i]; + ELSE + b[i]:= b[i - 1]; + END + END; + END Resi; + + PROCEDURE Ispis(n: CARDINAL); + BEGIN + IF n > 0 THEN + IF b[n] = b[n - 1] THEN + Ispis(n - 1); + ELSE + Ispis(n - 2); + WrInt(a[n], 8); + END; + END; + END Ispis; + +BEGIN + Unos; + Resi; + WrStr('Podniz: '); + Ispis(n); +END NizDin.