Program PAS; Const N = 14; Var A:Array[1..N] of integer; i,Max,Min:integer; Begin Randomize; Write('Исходный массив:'); For i:= 1 to N do Begin A[i]:=random(90)+1; Write(' ',A[i]); End; WriteLn; Max:=1; Min:=1; For i:= 2 to N do Begin if A[i]>A[Max] then Max:=i; if A[i]<A[Min] then Min:=i; End; WriteLn('Max(A) = A[',Max,'] = ',A[Max]); WriteLn('Min(A) = A[',Min,'] = ',A[Min]) End.
DIM n AS INTEGER CLS INPUT "N=", n REDIM a(1 TO n) AS INTEGER DIM a AS INTEGER RANDOMIZE TIMER FOR i = 1 TO n a(i) = 9 * RND + 1 PRINT a(i); NEXT i PRINT ' SORT DIM j AS INTEGER, t AS INTEGER FOR i = 1 TO n FOR j = 1 TO n IF a(i) < a(j) THEN t = a(i): a(i) = a(j): a(j) = t END IF NEXT j NEXT i ' t = a(1): j = 1 FOR i = 2 TO n IF a(i) = t THEN j = j + 1 ELSE PRINT t; "-"; j t = a(i): j = 1 END IF NEXT i PRINT t; "-"; j
Const
N = 14;
Var
A:Array[1..N] of integer;
i,Max,Min:integer;
Begin
Randomize;
Write('Исходный массив:');
For i:= 1 to N do
Begin
A[i]:=random(90)+1;
Write(' ',A[i]);
End;
WriteLn;
Max:=1;
Min:=1;
For i:= 2 to N do
Begin
if A[i]>A[Max] then Max:=i;
if A[i]<A[Min] then Min:=i;
End;
WriteLn('Max(A) = A[',Max,'] = ',A[Max]);
WriteLn('Min(A) = A[',Min,'] = ',A[Min])
End.
Пример:
Исходный массив: 66 70 88 36 30 11 53 1 57 77 6 40 65 46
Max(A) = A[3] = 88
Min(A) = A[8] = 1
DIM n AS INTEGER
CLS
INPUT "N=", n
REDIM a(1 TO n) AS INTEGER
DIM a AS INTEGER
RANDOMIZE TIMER
FOR i = 1 TO n
a(i) = 9 * RND + 1
PRINT a(i);
NEXT i
PRINT
' SORT
DIM j AS INTEGER, t AS INTEGER
FOR i = 1 TO n
FOR j = 1 TO n
IF a(i) < a(j) THEN
t = a(i): a(i) = a(j): a(j) = t
END IF
NEXT j
NEXT i
'
t = a(1): j = 1
FOR i = 2 TO n
IF a(i) = t THEN
j = j + 1
ELSE
PRINT t; "-"; j
t = a(i): j = 1
END IF
NEXT i
PRINT t; "-"; j
Пример
N=10
7 5 2 7 3 3 5 9 7 6
2 - 1
3 - 2
5 - 2
6 - 1
7 - 3
9 - 1