Ввод нуля означает завершение ввода(он нигде не учитывается)
program test; var sum, x, counter, sumOfNegative, sumOfPositive: integer; average: real; begin sum:=0; average:=0; counter:=0; sumOfPositive:=0; sumOfNegative:=0; read(x);
while x <> 0 do begin sum:=sum+x; average:=average+x; counter:=counter+1; if x > 0 then sumOfPositive:=sumOfPositive+x else sumOfNegative:=sumOfNegative+x; read(x); end;
average:=average/counter;
writeln('Sum = ', sum); writeln('Arithmetic average = ', average); writeln('The sum of positive numbers = ', sumOfPositive); writeln('The sum of negative numbers = ', sumOfNegative); readln; end.
Паскаль
1)Program abc; Uses crt;
var S:integer; a:array [1..10,1..10];
begin
For i:=1 to 10 do
For j:=1 to 10 do
read(a[i,j]);
writeln;
begin
S:=0;
For i:=1 to 10 do
For j:=1 to 10 do
if i=j then S:=S+a[i,j];
write('Сумма равна',S)
end.
2)
Program abc; Uses crt;
var min:integer; a:array [1..10,1..10];
begin
For i:=1 to 10 do
For j:=1 to 10 do
read(a[i,j]);
writeln;
min:=a[1,1];
For i:=1 to 10 do
For j:=1 to 10 do
if a[i,j]<min then min:=a[i,j];
writeln('Минимальный элемент равен',min);
end.
Ввод нуля означает завершение ввода(он нигде не учитывается)
program test;
var sum, x, counter, sumOfNegative, sumOfPositive: integer; average: real;
begin
sum:=0;
average:=0;
counter:=0;
sumOfPositive:=0;
sumOfNegative:=0;
read(x);
while x <> 0 do
begin
sum:=sum+x;
average:=average+x;
counter:=counter+1;
if x > 0 then
sumOfPositive:=sumOfPositive+x
else
sumOfNegative:=sumOfNegative+x;
read(x);
end;
average:=average/counter;
writeln('Sum = ', sum);
writeln('Arithmetic average = ', average);
writeln('The sum of positive numbers = ', sumOfPositive);
writeln('The sum of negative numbers = ', sumOfNegative);
readln;
end.