Var a: array[1..100] of integer; i,n,bg,nd,s: integer; begin write('n = '); readln(n); randomize; bg:=0; nd:=0; for i:=1 to n do begin a[i]:=random(10); write(a[i],' '); if a[i]=0 then if (bg>0) and (nd=0) then nd:=i else if bg=0 then bg:=i; end; writeln; if bg+nd>1 then begin if (bg mod 2=0) then inc(bg) else bg:=bg+2; if (nd mod 2=0) then dec(nd) else nd:=nd-2; writeln('начало: ',bg,' конец: ',nd); s:=1; repeat s:=s*a[bg]; bg:=bg+2; until bg>nd; writeln('произведение: ',s); end else writeln(0); end.
i,n,bg,nd,s: integer;
begin
write('n = '); readln(n);
randomize;
bg:=0; nd:=0;
for i:=1 to n do
begin
a[i]:=random(10);
write(a[i],' ');
if a[i]=0 then
if (bg>0) and (nd=0) then nd:=i
else if bg=0 then bg:=i;
end;
writeln;
if bg+nd>1 then
begin
if (bg mod 2=0) then inc(bg)
else bg:=bg+2;
if (nd mod 2=0) then dec(nd)
else nd:=nd-2;
writeln('начало: ',bg,' конец: ',nd);
s:=1;
repeat
s:=s*a[bg];
bg:=bg+2;
until bg>nd;
writeln('произведение: ',s);
end
else writeln(0);
end.
n = 15
4 4 7 0 3 5 6 1 1 8 8 4 0 1 9
начало: 5 конец: 11
произведение: 144
#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
int main() {
int N, M, sum;
cout << "Vvedite N = "; cin >> N;
cout << "Vvedite M = "; cin >> M;
int **Arr = new int* [N];
for (int i = 0; i < N; i++)
Arr[i] = new int [M];
srand(time(0));
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
Arr[i][j] = rand() % 51;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
cout << setw(4) << setprecision(2) << Arr[i][j] << " ";
cout << endl;
}
cout << endl;
for (int j = 0; j < M; j++)
{
sum = 0;
for (int i = 0; i < N; i++)
sum = sum + Arr[i][j];
cout << setw(4) << setprecision(2) << sum << " ";
}
cout << endl;
system("pause");
return 0;
}