Pascal: 1) const n = 10; var a:array [1..n] of integer; i:integer; begin randomize; for i:=1 to n do begin a[i]:=random(21)-10; write (a[i]:3); end; writeln; for i:=1 to n do begin if a[i]>0 then a[i]:=99; write (a[i]:3); end; writeln; end.
2) const n = 10; var a:array [1..n] of integer; p,s,i:longint; begin p:=1; s:=0; randomize; for i:=1 to n do begin a[i]:=random(21)-10; if a[i]>0 then p:=p*a[i] else if a[i]<0 then s:=s+a[i]; write(a[i]:3); end; writeln; writeln ('Proizvedenie: ',p); writeln ('Summa: ',s); end.
Const n=?; {Кол-во элементов в массиве, написать число вместо "?"} Var a,b:array[1..n] of integer; x,k,i,j:integer; Begin writeln('Init massive:'); for i:=1 to n do begin readln(x); {а лучше написать read(x); и вводить числа через пробел одной строкой, красивее будет} a[i]:=x; end; k:=n div 2; if (n mod 2)<>0 then k:=k+1; j:=1; for i:=(k+1) to n do begin b[j]:=a[i]; j:=j+1; end; if (n mod 2)<>0 then begin b[k]:=a[k]; k:=k-1; j:=j+1; end; for i:=1 to k do begin b[j]:=a[i]; j:=j+1; end; for i:=1 to n do write(b[i],' '); End.
1)
const n = 10;
var a:array [1..n] of integer;
i:integer;
begin
randomize;
for i:=1 to n do
begin
a[i]:=random(21)-10;
write (a[i]:3);
end;
writeln;
for i:=1 to n do
begin
if a[i]>0 then a[i]:=99;
write (a[i]:3);
end;
writeln;
end.
2)
const n = 10;
var a:array [1..n] of integer;
p,s,i:longint;
begin
p:=1;
s:=0;
randomize;
for i:=1 to n do
begin
a[i]:=random(21)-10;
if a[i]>0 then p:=p*a[i] else
if a[i]<0 then s:=s+a[i];
write(a[i]:3);
end;
writeln;
writeln ('Proizvedenie: ',p);
writeln ('Summa: ',s);
end.
C++:
1)
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int a[10];
srand (time(NULL));
for (int i = 0; i<10; i++)
{
a[i] = rand()%20-10;
cout <<a[i] <<" ";
if (a[i]>0)
a[i] = 99;
}
cout <<endl;
for (int i = 0; i<10; i++)
cout <<a[i] <<" ";
cout <<endl;
return 0;
}
2)
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int a[10];
int p = 1,s = 0;
srand (time(NULL));
for (int i = 0; i<10; i++)
{
a[i] = rand()%20-10;
cout <<a[i] <<" ";
if (a[i]>0)
p*=a[i];
else if (a[i]<0) s+=a[i];
}
cout <<endl;
cout <<"Summa: " <<s <<endl
<<"Proizvedenie: " <<p <<endl;
return 0;
}
Var a,b:array[1..n] of integer;
x,k,i,j:integer;
Begin
writeln('Init massive:');
for i:=1 to n do
begin
readln(x); {а лучше написать read(x); и вводить числа через пробел одной строкой, красивее будет}
a[i]:=x;
end;
k:=n div 2;
if (n mod 2)<>0 then k:=k+1;
j:=1;
for i:=(k+1) to n do
begin
b[j]:=a[i];
j:=j+1;
end;
if (n mod 2)<>0 then
begin
b[k]:=a[k];
k:=k-1;
j:=j+1;
end;
for i:=1 to k do
begin
b[j]:=a[i];
j:=j+1;
end;
for i:=1 to n do write(b[i],' ');
End.