Исходный массив: -3 -4 -1 -8 6 Max1 = A[5] = 6 Max2 = A[3] = -1 Max3 = A[1] = -3 Новый массив: 1 -4 3 -8 5Const N = 5; Var A:array[1..N] of integer; i,Max1,Max2,Max3:integer; Begin Randomize; Write('Исходный массив:'); For i:= 1 to N do Begin A[i]:=random(21)-10; Write(' ',A[i]); End;
Max1:=1; For i:= 2 to N do if A[i]>A[Max1] then Max1:=i;
if Max1<>1 then Max2:=1 else Max2:=2; For i:= 1 to N do if (A[i]>A[Max2])and(A[i]<=A[Max1])and(i<>Max1) then Max2:=i;
Max3:=1; if (Max2=Max3)or(Max1=Max3) then Max3:=Max3+1; if (Max2=Max3)or(Max1=Max3) then Max3:=Max3+1; For i:= 1 to N do if (A[i]>A[Max3])and(A[i]<=A[Max2])and(i<>Max2) then Max3:=i;
1) program z1; uses crt; var a: integer; begin clrscr; repeat write('enter a: '); readln(a) until (a>=10000) and (a<=99999); a:=a div 10; Writeln (a); Readkey; End. 2) program z2; uses crt; var a: integer; begin clrscr; repeat write('enter a: '); readln(a) until (a>=10000) and (a<=99999); a:=a mod 1000; Writeln (a); Readkey; End. 3) program z3; uses crt; var a, b: integer; begin clrscr; repeat write('enter a: '); readln(a) until (a>=10000) and (a<=99999); b:=a mod 10; a:=a div 100; Writeln (a, b); Readkey; End. 4) program z4; uses crt; var a: integer; begin clrscr; repeat write('enter a: '); readln(a) until (a>=10000) and (a<=99999); a:=a div 1000; Writeln (a); Readkey; End.
Max1 = A[5] = 6
Max2 = A[3] = -1
Max3 = A[1] = -3
Новый массив: 1 -4 3 -8 5Const
N = 5;
Var
A:array[1..N] of integer;
i,Max1,Max2,Max3:integer;
Begin
Randomize;
Write('Исходный массив:');
For i:= 1 to N do
Begin
A[i]:=random(21)-10;
Write(' ',A[i]);
End;
Max1:=1;
For i:= 2 to N do
if A[i]>A[Max1] then Max1:=i;
if Max1<>1 then Max2:=1
else Max2:=2;
For i:= 1 to N do
if (A[i]>A[Max2])and(A[i]<=A[Max1])and(i<>Max1) then Max2:=i;
Max3:=1;
if (Max2=Max3)or(Max1=Max3) then Max3:=Max3+1;
if (Max2=Max3)or(Max1=Max3) then Max3:=Max3+1;
For i:= 1 to N do
if (A[i]>A[Max3])and(A[i]<=A[Max2])and(i<>Max2) then Max3:=i;
WriteLn;
WriteLn('Max1 = A[',Max1,'] = ',A[Max1]);
WriteLn('Max2 = A[',Max2,'] = ',A[Max2]);
WriteLn('Max3 = A[',Max3,'] = ',A[Max3]);
A[Max1]:=Max1;
A[Max2]:=Max2;
A[Max3]:=Max3;
Write('Новый массив:');
For i:= 1 to N do
Write(' ',A[i])
End.
Пример работы программы:
Исходный массив: -3 -4 -1 -8 6
Max1 = A[5] = 6
Max2 = A[3] = -1
Max3 = A[1] = -3
Новый массив: 1 -4 3 -8 5