Delphida massivlar bilan ishlash algoritmlarga doir misollar 1-masala


Download 257.5 Kb.
bet1/7
Sana02.02.2023
Hajmi257.5 Kb.
#1146880
  1   2   3   4   5   6   7
Bog'liq
Delphida ishlash algoritmlarga doir misollar


Delphida massivlar bilan ishlash algoritmlarga doir misollar
4.1-masala. A(1), A(2)….,A(N) ketma-ketlikda berilgan jadval elementlarini teskari tartibda ekranga chiqaring.
procedure TForm1.Button1Click(Sender: TObject);
begin
N:=StrToInt(Edit1.Text);
StringGrid1.ColCount:=N;
StringGrid2.ColCount:=N;
end;
procedure TForm1.Button2Click(Sender: TObject);
var a,a1,k:real;I:byte;
begin
for I:=0 TO n-2 div 2 DO begin
a:=StrToFloat(StringGrid1.Cells[i,0]);
a1:=StrToFloat(StringGrid1.Cells[n-i-1,0]);
begin k:=a;a:=a1;a1:=k;
StringGrid2.Cells[i,0]:=FloatToStr(a);
StringGrid2.Cells[i+1,0]:=FloatToStr(a1);
end;end;end;
end.

4.2-masala. N ta elementdan tashkil topgan massivning elementlari yig’indisini toping.
procedure TForm1.Button1Click(Sender: TObject);
begin
N:=StrToInt(Edit1.Text);
StringGrid1.ColCount:=N;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
S:=0;
FOR I:=0 TO n-1 DO
S:=S+STRTOFLOAT(StringGrid1.Cells[I,0]);
Edit2.Text:= FloatToStr(S);
end;
end.
4.3-masala. N ta elementdan iborat bir o’lchovli massiv elementalarini kiritng va ularni ekranga chiqaring.
Yechish. Birinchi sikl yordamida massiv elementalarini kiritamiz. Ikkinchi sikl yordamida ularni ekranga chiqaramiz.
procedure TForm1.Button1Click(Sender: TObject);
begin
N:=StrToInt(Edit1.Text);
StringGrid1.ColCount:=N;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Clear;
FOR I:=0 TO n-1 DO
memo1.Lines.Add(inttostr(i+1)+'-element '+StringGrid1.Cells[i,0]);
end;
end.
4.4-masala.N ta elementdan iborat bir o’lchovli massaviy elementlarning yig’indisi S va manfiy elementlar soni K ni aniqlang.
Yechish. Birinchi sikl yordamida massiv elementalarini kiritamiz. Ikkinchi sikl yordamida massiv elementalarining yig’indisini hamda manfiy elementlar sonini hisoblaymiz.
procedure TForm1.Button1Click(Sender: TObject);
VAR N:Integer;
begin
N:=StrToInt(Edit1.Text);
StringGrid1.ColCount:=N;
end;
procedure TForm1.Button2Click(Sender: TObject);
var S:REAL;
I,k:INTEGER;
begin
S:=0;k:=0;
FOR I:=0 TO strtoint(Edit1.Text)-1 DO
S:=S+STRTOFLOAT(StringGrid1.Cells[I,0]);
Edit2.Text:= FloatToStr(S);
FOR I:=0 TO strtoint(Edit1.Text)-1 DO
if STRTOFLOAT(StringGrid1.Cells[I,0])<0 then k:=k+1;
Edit3.Text:=inttostr(k);
end;
end.

Download 257.5 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling