Unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);var i, j, n: integer; min, max, var_bl: real; a: array of array of real;beginMemo1.Clear;if TryStrToInt(Edit1.Text,n) thenbegin n:=StrToInt(Edit1.Text); if n<1 then begin Application.MessageBox('Ошибка!','',0); Exit; end; SetLength(a,n); for i:= 0 to n-1 do SetLength(a[i],n); Randomize; for i:= 0 to n-1 do for j:=0 to n-1 do a[i,j]:=Random(100)-30; min:= a[0,0]; max:= a[0,0]; for i:= 0 to n-1 do begin for j:=0 to n-1 do begin //Memo1.Text:=Memo1.Text+FloatToStrF(a[i,j],ffFixed,5,3)+' ';//Форматированный вывод Memo1.Text:=Memo1.Text+FloatToStr(a[i,j])+' '; //обычный вывод end; Memo1.Lines.Add(''); end; for i:= 0 to n-1 do for j:=0 to n-1 do begin if(a[i,j]<min) then min:=a[i,j]; if(a[i,j]>max) then max:=a[i,j]; end; Memo1.Lines.Add('Min='+FloatToStr(min)+', Max='+FloatToStr(max)); for i:= 0 to n-1 do for j:=0 to n-1 do begin if(a[i,j]=min) then begin a[i,j]:= max; Continue; end; if(a[i,j]=max) then a[i,j]:=min; end; Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add('Были поменяны наименьший и наибольший элемент массива'); Memo1.Lines.Add(''); for i:= 0 to n-1 do begin for j:=0 to n-1 do begin //Memo1.Text:=Memo1.Text+FloatToStrF(a[i,j],ffFixed,5,3)+' ';//Форматированный вывод Memo1.Text:=Memo1.Text+FloatToStr(a[i,j])+' '; //обычный вывод end; Memo1.Lines.Add(''); end; Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add('');end else Application.MessageBox('Ошибка!','',0);end; end.
Program task; var p:array[1..10] of integer; i, n2, n3, n4, n5:integer; begin n2:=0; n3:=0; n4:=0; n5:=0; {n2 - n5 - колич. 2-ек, 3-ек и т.д.} writeln('Введите 10 элементов массива, отметки от 1 до 5'); for i:=1 to 10 do {ввод исходных данных} begin write('p[',i,'] = '); readln(p[i]) end; for i:=1 to 10 do {решение, перебор таблицы и суммирование} begin if p[i] = 2 then n2:=n2+1; if p[i] = 3 then n3:=n3+1; if p[i] = 4 then n4:=n4+1; if p[i] = 5 then n5:=n5+1 end; writeln('n2 = ',n2); {вывод результатов} writeln('n3 = ',n3); writeln('n4 = ',n4); writeln('n5 = ',n5); writeln('всего оценок',n2+n3+n4+n5) end.
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Memo1: TMemo; Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);var i, j, n: integer; min, max, var_bl: real; a: array of array of real;beginMemo1.Clear;if TryStrToInt(Edit1.Text,n) thenbegin n:=StrToInt(Edit1.Text); if n<1 then begin Application.MessageBox('Ошибка!','',0); Exit; end; SetLength(a,n); for i:= 0 to n-1 do SetLength(a[i],n); Randomize; for i:= 0 to n-1 do for j:=0 to n-1 do a[i,j]:=Random(100)-30; min:= a[0,0]; max:= a[0,0]; for i:= 0 to n-1 do begin for j:=0 to n-1 do begin //Memo1.Text:=Memo1.Text+FloatToStrF(a[i,j],ffFixed,5,3)+' ';//Форматированный вывод Memo1.Text:=Memo1.Text+FloatToStr(a[i,j])+' '; //обычный вывод end; Memo1.Lines.Add(''); end;
for i:= 0 to n-1 do for j:=0 to n-1 do begin if(a[i,j]<min) then min:=a[i,j]; if(a[i,j]>max) then max:=a[i,j]; end; Memo1.Lines.Add('Min='+FloatToStr(min)+', Max='+FloatToStr(max)); for i:= 0 to n-1 do for j:=0 to n-1 do begin if(a[i,j]=min) then begin a[i,j]:= max; Continue; end; if(a[i,j]=max) then a[i,j]:=min; end; Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add('Были поменяны наименьший и наибольший элемент массива'); Memo1.Lines.Add(''); for i:= 0 to n-1 do begin for j:=0 to n-1 do begin //Memo1.Text:=Memo1.Text+FloatToStrF(a[i,j],ffFixed,5,3)+' ';//Форматированный вывод Memo1.Text:=Memo1.Text+FloatToStr(a[i,j])+' '; //обычный вывод end; Memo1.Lines.Add(''); end; Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add('');end else Application.MessageBox('Ошибка!','',0);end;
end.