Uses Crt; const n=5; m=7; type Mas = array [1..n, 1..m] of integer; var i, j, j1, j2: integer; Sumj1, Sumj2: real; A: Mas; begin ClrScr; Randomize; SumJ1:=0; SumJ2:=0; for i:=1 to n do for j:=1 to m do A[i,j]:=random (10); WriteLn (' Massiv A: '); for i:=1 to n do begin for j:=1 to m do Write (A[i,j]:4); WriteLn; end; WriteLn; repeat Write (' Stolbez #1 = '); ReadLn(j1); until (j1>=1) and (j1<=m); repeat Write (' Stolbez #2 = '); ReadLn(j2); until (j2>=1) and (j2<=m) and (j1<>j2); for i:= 1 to n do SumJ1 := SumJ1+A[i,j1]; for i:= 1 to n do SumJ2:=SumJ2+A[i,j2]; SumJ1:=SumJ1/n; SumJ2:=SumJ2/n; WriteLn; WriteLn (' Srednee stolbza ', j1, ' = ', SumJ1:4:2); WriteLn (' Srednee stolbza ', j2, ' = ', SumJ2:4:2); ReadLn; end.
ответ на Python:
a = list(map(int,input().split())) #Принимаем массив из одной строки
s = 0 #Счётчик
for i in range(len(a)-2): #Проход по массиву до пред-предпоследнего элемента
if a[i] == (a[i+1] + a[i+2]) / 2: # Проверяем, является ли этот элемент средним арифметическим 2-х следующих
s += 1 #Прибавляем счётчик
print(s) #Выводим ответ
Или вот:
a = list(map(int,input().split()))
s = 0
for i in range(len(a)-2):
a1 = a[i+1]
a2 = a[i+2]
if a[i] == (a1 + a2) / 2:
s += 1
print(s)
Объяснение:
const n=5; m=7;
type Mas = array [1..n, 1..m] of integer;
var i, j, j1, j2: integer;
Sumj1, Sumj2: real;
A: Mas;
begin
ClrScr;
Randomize;
SumJ1:=0; SumJ2:=0;
for i:=1 to n do
for j:=1 to m do
A[i,j]:=random (10);
WriteLn (' Massiv A: ');
for i:=1 to n do
begin
for j:=1 to m do
Write (A[i,j]:4);
WriteLn;
end; WriteLn;
repeat
Write (' Stolbez #1 = '); ReadLn(j1);
until (j1>=1) and (j1<=m);
repeat
Write (' Stolbez #2 = '); ReadLn(j2);
until (j2>=1) and (j2<=m) and (j1<>j2);
for i:= 1 to n do
SumJ1 := SumJ1+A[i,j1];
for i:= 1 to n do
SumJ2:=SumJ2+A[i,j2];
SumJ1:=SumJ1/n; SumJ2:=SumJ2/n;
WriteLn;
WriteLn (' Srednee stolbza ', j1, ' = ', SumJ1:4:2);
WriteLn (' Srednee stolbza ', j2, ' = ', SumJ2:4:2);
ReadLn;
end.