Массивы написать программу в pascalabc.net : даны x1, x10 и y1, y10. сравнить их суммы и если сумма х будет больше суммы y, то все y обнулить, иначе обнулить все х.
const n=10; var x,y:array[1..n] of integer; sx,sy,i:integer; begin Randomize; Write('X: '); sx:=0; for i:=1 to n do begin x[i]:=Random(101)-50; Write(x[i],' '); sx:=sx+x[i] end; Writeln; Write('Y: '); sy:=0; for i:=1 to n do begin y[i]:=Random(101)-50; Write(y[i],' '); sy:=sy+y[i] end; Writeln; Writeln('Сумма х= ',sx,', сумма y= ',sy); if sx>sy then for i:=1 to n do y[i]:=0 else for i:=1 to n do x[i]:=0; Write('X: '); for i:=1 to n do Write(x[i],' '); Writeln; Write('Y: '); for i:=1 to n do Write(y[i],' '); Writeln end.
var i,sumX, sumY: integer; x: array [1..10] of integer; y: array [1..10] of integer; begin sumX:=0; sumy:=0; //çàïîëíèì ìàññèâ x for i:=1 to 10 do begin read (x[i]); sumX:=sumX+x[i] end; //çàïîëíèì ìàññèâ y for i:=1 to 10 do begin read (y[i]); sumY:=sumY+y[i] end; writeln ('sumx=',sumx,'sumy=',sumy); if sumX>sumY then for i:=1 to 10 do y[i]:=0;
if sumX<sumY then for i:=1 to 10 do x[i]:=0;
for i:=1 to 10 do writeln ('x[',i,']=',x[i],'y[',i,']=',y[i]); end.
const
n=10;
var
x,y:array[1..n] of integer;
sx,sy,i:integer;
begin
Randomize;
Write('X: ');
sx:=0;
for i:=1 to n do begin
x[i]:=Random(101)-50;
Write(x[i],' ');
sx:=sx+x[i]
end;
Writeln;
Write('Y: ');
sy:=0;
for i:=1 to n do begin
y[i]:=Random(101)-50;
Write(y[i],' ');
sy:=sy+y[i]
end;
Writeln;
Writeln('Сумма х= ',sx,', сумма y= ',sy);
if sx>sy then for i:=1 to n do y[i]:=0
else for i:=1 to n do x[i]:=0;
Write('X: ');
for i:=1 to n do Write(x[i],' ');
Writeln;
Write('Y: ');
for i:=1 to n do Write(y[i],' ');
Writeln
end.
Пример
X: 4 29 -50 -18 37 -43 -18 9 41 28
Y: -8 41 -18 -6 -10 -10 47 -8 -29 25
Сумма х= 19, сумма y= 24
X: 0 0 0 0 0 0 0 0 0 0
Y: -8 41 -18 -6 -10 -10 47 -8 -29 25
2. Аналогичное решение средствами PascalABC.Net 3.2
const
n=10;
begin
var x:=ArrRandom(n,-50,50); Write('X: '); x.Println;
var y:=ArrRandom(n,-50,50); Write('Y: '); y.Println;
var sx:=x.Sum; var sy:=y.Sum;
Writeln('Сумма х= ',sx,', сумма y= ',sy);
if sx>sy then y:=ArrFill(n,0) else x:=ArrFill(n,0);
Write('X: '); x.Println;
Write('Y: '); y.Println
end.
Выбирать вам...)))
var
i,sumX, sumY: integer;
x: array [1..10] of integer;
y: array [1..10] of integer;
begin
sumX:=0; sumy:=0;
//çàïîëíèì ìàññèâ x
for i:=1 to 10 do
begin
read (x[i]);
sumX:=sumX+x[i]
end;
//çàïîëíèì ìàññèâ y
for i:=1 to 10 do
begin
read (y[i]);
sumY:=sumY+y[i]
end;
writeln ('sumx=',sumx,'sumy=',sumy);
if sumX>sumY then for i:=1 to 10 do y[i]:=0;
if sumX<sumY then for i:=1 to 10 do x[i]:=0;
for i:=1 to 10 do
writeln ('x[',i,']=',x[i],'y[',i,']=',y[i]);
end.