Const n=6; m=8; var a:array[1..n,1..m] of integer; i,j,max,min,s:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to m do begin a[i,j]:=random(51)-25; write(a[i,j]:4); end; writeln; end; max:=abs(a[1,1]); min:=abs(a[1,1]); s:=0; for i:=1 to n do for j:=1 to m do begin if a[i,j]>0 then s:=s+a[i,j]; if abs(a[i,j])>max then max:=abs(a[i,j]); if abs(a[i,j])<min then min:=abs(a[i,j]); end; writeln('s = ',s,' max = ',max,' min = ',min); writeln('s - max * min = ',s-max*min); end.
#include <iostream>
#define K 20
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
float arr[K], mid = 0;
cout << "Исходный массив: ";
for(size_t i = 0; i < K; ++i){
arr[i] = (rand() % 50000 - 25000)/17.0; // Заполняем случайными числами
mid += arr[i];
cout << arr[i] << " ";
}
mid /= K;
cout << endl << "Среднее арифм.: " << mid << endl;
int minI, maxI;
minI = maxI = 5*1;
cout << "Результирующий массив: ";
for(size_t i = 2; i < K/5; ++i){
if(arr[minI] > arr[5*i])
minI = 5*i;
if(arr[maxI] < arr[5*i])
maxI = 5*i;
}
arr[maxI] = arr[minI] = mid;
for(size_t i = 0; i < K; ++i)
cout << arr[i] << " ";
cout << endl;
system("pause");
return 0;
}
var
a:array[1..n,1..m] of integer;
i,j,max,min,s:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to m do
begin
a[i,j]:=random(51)-25;
write(a[i,j]:4);
end;
writeln;
end;
max:=abs(a[1,1]); min:=abs(a[1,1]); s:=0;
for i:=1 to n do
for j:=1 to m do
begin
if a[i,j]>0 then s:=s+a[i,j];
if abs(a[i,j])>max then max:=abs(a[i,j]);
if abs(a[i,j])<min then min:=abs(a[i,j]);
end;
writeln('s = ',s,' max = ',max,' min = ',min);
writeln('s - max * min = ',s-max*min);
end.
Пример:
Исходный массив:
-10 4 9 -21 9 24 24 -24
-23 -21 21 24 -18 -15 14 -8
2 -23 -17 5 17 -8 -10 -16
-22 -9 6 -21 3 -13 18 13
-8 -3 -25 -6 -2 8 14 25
-19 -10 22 -1 -6 -20 -5 -17
s = 262 max = 25 min = 1
s - max * min = 237