Lazarus is free and therefore seems like an interesting alternative.
function is_First(mvalue:Integer):Boolean;
var i,suma:Integer;
begin
suma:=0;
for i:=1 to mvalue+1 do
begin
if mvalue mod i=0 then
suma:=suma+1;
end;
if suma=2 then
is_First:=True
else
is_First:=False;
end;
function sum_Tab(tab: array of Integer; size:Integer): Integer;
var i,sum:Integer;
begin
sum:=0;
for i:=0 to size do
sum:=sum+tab[i];
sum_Tab:=sum;
end;
function min_Tab(tab: array of Integer; size: Integer): Integer;
var i,min: Integer;
begin
min:=tab[0];
for i:=1 to size do
begin
if min>tab[i] then
min:=tab[i];
end;
min_Tab:=min;
end;
function max_Tab(tab: array of Integer; size: Integer): Integer;
var i,max: Integer;
begin
max:=tab[0];
for i:=1 to size do
begin
if max<tab[i] then
max:=tab[i];
end;
max_Tab:=max;;
end;
function aver_Tab1(tab: array of Integer; size: Integer):Real;
begin
aver_Tab1:=(1.00*sum_Tab(tab,size))/(1.00*size);
end;
function aver_Tab2(tab: array of Integer; size: Integer):Real;
begin
aver_Tab2:=((1.00*min_Tab(tab,size))+(1.00*max_Tab(tab,size)))/2.00;
end;
{ TForm1 }
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
pascalsA: array of Integer;
i,j,m1,m2,s:Integer;
a1,a2: Real;
begin
setLength(pascalsA,30);
i:=0;
j:=1;
repeat
if is_First(j) then
begin
pascalsA[i]:=j;
i:=i+1;
end ;
j:=j+1;
until i>30;
for i:=0 to 29 do
begin
ListBox1.Items.Add(IntToStr(i+1)+') '+IntToStr(pascalsA[i]));
end;
m1:=min_Tab(pascalsA,29);
m2:=max_Tab(pascalsA,29);
s:=sum_Tab(pascalsA,29);
a1:=aver_Tab1(pascalsA,29);
a2:=aver_Tab2(pascalsA,29);
Label6.Caption:=IntToStr(m1);
Label7.Caption:=IntToStr(m2);
Label8.Caption:=IntToStr(s);
Label9.Caption:=FloatToStr(a1);
Label10.Caption:=FloatToStr(a2);
end;
end.
Brak komentarzy:
Prześlij komentarz