Скорее всего так: const n=5; var a:array[1..n] of integer; i,s,r:integer; begin Randomize; writeln('Массив A:'); for i:=1 to n do begin a[i]:=random(101)-50; write(a[i]:4); end; writeln; s:=0; r:=0; for i:=1 to n do if a[i]>0 then s:=s+a[i] else r:=r-a[i]; writeln('s = ',s,' r = ',r); end.
const n=5;
var a:array[1..n] of integer;
i,s,r:integer;
begin
Randomize;
writeln('Массив A:');
for i:=1 to n do
begin
a[i]:=random(101)-50;
write(a[i]:4);
end;
writeln;
s:=0; r:=0;
for i:=1 to n do
if a[i]>0 then s:=s+a[i] else r:=r-a[i];
writeln('s = ',s,' r = ',r);
end.
Пример:
Массив A:
29 32 -48 -42 11
s = 72 r = 90
#include <stdlib.h>
#include <ctime>
using namespace std;
int main() {
int a[5], p = 0, n = 0;
srand ( time(NULL) );
for (int i = 0 ; i < 5 ; i++) {
a[i]=rand()%100-50;
cout << a[i] << ' ';
if(a[i] > 0) p+=a[i];
else n-=a[i];
}
cout << endl << p << ' ' << n << endl;
}