const n=5; var a:array[1..n,1..n] of integer; x:array[1..n] of double; i,j,k:byte; begin Randomize; Writeln('*** Исходный массив ***'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(51)-25; Write(a[i,j]:4) end; Writeln end; Writeln('*** Массив x ***'); for j:=1 to n do begin x[j]:=0; k:=0; for i:=1 to n do if a[i,j] mod 2=0 then begin x[j]:=x[j]+a[i,j]; Inc(k) end; if k>0 then x[j]:=x[j]/k; Write(x[j]:0:5,' ') end; Writeln end.
#include <iostream> #include <cstdlib> #include <ctime> int main() { using namespace std; cout << "Enter size of array: "; int N; cin >> N; int * ARR = new int[N]; srand(time(0)); int i; for (i = 0; i < N; ++i) ARR[i] = rand() % 100 + 1;
cout << "Here is an original array:\n"; for (i = 0; i < N; ++i) cout << ARR[i] << " "; cout << endl;
int temp = ARR[N - 1]; for (i = N - 1; i > 0; --i) ARR[i] = ARR[i - 1]; ARR[0] = temp;
cout << "\nHere is a new array:\n"; for (i = 0; i < N; ++i) cout << ARR[i] << " "; cout << endl;
const
n=5;
var
a:array[1..n,1..n] of integer;
x:array[1..n] of double;
i,j,k:byte;
begin
Randomize;
Writeln('*** Исходный массив ***');
for i:=1 to n do begin
for j:=1 to n do begin
a[i,j]:=Random(51)-25;
Write(a[i,j]:4)
end;
Writeln
end;
Writeln('*** Массив x ***');
for j:=1 to n do begin
x[j]:=0; k:=0;
for i:=1 to n do
if a[i,j] mod 2=0 then begin
x[j]:=x[j]+a[i,j]; Inc(k)
end;
if k>0 then x[j]:=x[j]/k;
Write(x[j]:0:5,' ')
end;
Writeln
end.
Тестовое решение:
*** Исходный массив ***
-10 18 -8 -15 5
-21 -18 6 -2 9
-7 22 -4 3 14
21 16 -10 -18 -9
17 3 -14 -18 12
*** Массив x ***
-10.00000 9.50000 -6.00000 -12.66667 13.00000
#include <cstdlib>
#include <ctime>
int main()
{
using namespace std;
cout << "Enter size of array: ";
int N;
cin >> N;
int * ARR = new int[N];
srand(time(0));
int i;
for (i = 0; i < N; ++i)
ARR[i] = rand() % 100 + 1;
cout << "Here is an original array:\n";
for (i = 0; i < N; ++i)
cout << ARR[i] << " ";
cout << endl;
int temp = ARR[N - 1];
for (i = N - 1; i > 0; --i)
ARR[i] = ARR[i - 1];
ARR[0] = temp;
cout << "\nHere is a new array:\n";
for (i = 0; i < N; ++i)
cout << ARR[i] << " ";
cout << endl;
return 0;
}