Vct tính tổng các phần tử âm trong tệp 18/07/2021 Bởi Alexandra Vct tính tổng các phần tử âm trong tệp
var a:array[1..100] of integer;n,i,s:integer; begin assign(input,’bt.inp’);reset(input); assign(output,’bt.out’);rewrite(output); readln(n); s:=0; for i:=1 to n do readln(a[i]); if a[i]<0 then s:=s+a[i]; write(s); close(input); close(output); end. Bình luận
var n,i,s,temp:integer;begin assign(input,’TT.INP’);reset(input); assign(output,’TT.OUT’);rewrite(output); readln(n); s:=0; for i:=1 to n do begin read(temp); if temp<0 then s:=s+temp; end; write(s); close(input); close(output);end. ==================================== Input: 5-1 2 -3 4 -5 Output: -9 Bình luận
var a:array[1..100] of integer;n,i,s:integer;
begin
assign(input,’bt.inp’);reset(input);
assign(output,’bt.out’);rewrite(output);
readln(n);
s:=0;
for i:=1 to n do readln(a[i]);
if a[i]<0 then s:=s+a[i];
write(s);
close(input);
close(output);
end.
var n,i,s,temp:integer;
begin
assign(input,’TT.INP’);reset(input);
assign(output,’TT.OUT’);rewrite(output);
readln(n);
s:=0;
for i:=1 to n do
begin
read(temp);
if temp<0 then s:=s+temp;
end;
write(s);
close(input);
close(output);
end.
====================================
Input:
5
-1 2 -3 4 -5
Output:
-9