Re: KDU5 /6. Histogram

{okomentuj riadky}
uses crt;
const n=80;
type pole=array[1..n] of byte;
var a:pole;
pocet,i:byte;
procedure nacitaj;
begin
i:=0;
writeln('Zadaj postupnost hodnot 1..25 ukoncenu 0:');
repeat
inc(i);
write(i:2,'. ');
readln(a[i]);
until (i=80) or (a[i]=0);
if a[i]=0 then pocet:=i-1;
end;
function maximum(a:pole):byte;
var max:byte;
begin
max:=1;
for i:=2 to pocet do
if a[i]>a[max] then max:=i;
maximum:=a[max]
end;
procedure histogram;
var sirka,vyska,xl,xp,yl:byte;
begin
clrscr;
sirka:=80 div pocet;
vyska:=25 div maximum(a);
xl:=0;xp:=0;
for i:=1 to pocet do
begin
xl:=xp+1;
xp:=xp+sirka;
yl:=26-a[i]*vyska;
window(xl,yl,xp,25);
textattr:=16*(((i-1) mod 7)+1);
clrscr;
gotoxy(sirka div 2,1);
write(a[i]:2);
readkey;
end;
window(1,1,80,25);
end;
begin
textattr:=15;
clrscr;
nacitaj;
histogram;
readln;
end.
uses crt;
const n=80;
type pole=array[1..n] of byte;
var a:pole;
pocet,i:byte;
procedure nacitaj;
begin
i:=0;
writeln('Zadaj postupnost hodnot 1..25 ukoncenu 0:');
repeat
inc(i);
write(i:2,'. ');
readln(a[i]);
until (i=80) or (a[i]=0);
if a[i]=0 then pocet:=i-1;
end;
function maximum(a:pole):byte;
var max:byte;
begin
max:=1;
for i:=2 to pocet do
if a[i]>a[max] then max:=i;
maximum:=a[max]
end;
procedure histogram;
var sirka,vyska,xl,xp,yl:byte;
begin
clrscr;
sirka:=80 div pocet;
vyska:=25 div maximum(a);
xl:=0;xp:=0;
for i:=1 to pocet do
begin
xl:=xp+1;
xp:=xp+sirka;
yl:=26-a[i]*vyska;
window(xl,yl,xp,25);
textattr:=16*(((i-1) mod 7)+1);
clrscr;
gotoxy(sirka div 2,1);
write(a[i]:2);
readkey;
end;
window(1,1,80,25);
end;
begin
textattr:=15;
clrscr;
nacitaj;
histogram;
readln;
end.