Первая задача (проверил, вроде работает, константа N - количество чисел в последовательности):
const N = 10; var number, count, i : integer; begin count := 1; for i := 1 to N do begin write('Input number: '); readln(number); if (number mod 3 = 0) and (number <> 0) then count := count * number; end; if (count = 1) then count := 0; writeln('Result: ',count); readln; end.
Вторая задача (проверил, работает, но мог недопонять условие): const N = 10; var number, positive, negative, i : integer; begin negative := 1; positive := 0; for i := 1 to N do begin write('Input number: '); readln(number); if (number > 0) then positive := positive + number; if (number < 0) then negative := negative * number; end; writeln('Positive sum: ',positive); writeln('Negative mul: ',negative); if (positive > negative) then writeln('Sum of positive numbers bigger than mul of negative numbers.') else if (positive < negative) then writeln('Sum of positive numbers lesser than mul of negative numbers.') else writeln('Sum of positive numbers and mul of negative numbers are equal.'); readln; end.
Третья задача (проверил, работает): const N = 10; var number, lastneg, prevneg, i : integer; begin lastneg := 100; prevneg := 100; for i := 1 to N do begin write('Input number: '); readln(number); if (number < 0) then if (lastneg > 0) then lastneg := number else begin prevneg := lastneg; lastneg := number; end; end; if (prevneg > 0) then writeln('This sequence of numbers contains less than two negative numbers.') else writeln('Penultimate negative number: ',prevneg); readln; end.
Var 1 Задача n, pr, i, a: integer; begin readln(n); pr := 0; for i := 1 to n do begin read(a); if (a mod 3 = 0) then if (pr > 0) then pr := pr * a else pr := a; end; writeln(pr); end. 2 Задача var n, i, pl, ot, a: integer; begin readln(n); pl := 0; ot := 0; for i := 1 to n do begin read(a); if (a >= 0) then inc(pl, a) else begin if (ot <> 0) then ot := ot * a else ot := a; end; end; if (pl > ot) then writeln('Polozitelnii) else writeln('Otricat'); end. var n, i, a, posl, prd: integer; begin readln(n); posl := 0; prd := 0; for i := 1 to n do begin read(a); if (a < 0) then begin prd := posl; posl := a; end; end; if (posl = 0) then writeln('Нет отрицательных') else writeln(prd); end.
const N = 10;
var number, count, i : integer;
begin
count := 1;
for i := 1 to N do
begin
write('Input number: ');
readln(number);
if (number mod 3 = 0) and (number <> 0) then
count := count * number;
end;
if (count = 1) then
count := 0;
writeln('Result: ',count);
readln;
end.
Вторая задача (проверил, работает, но мог недопонять условие):
const N = 10;
var number, positive, negative, i : integer;
begin
negative := 1; positive := 0;
for i := 1 to N do
begin
write('Input number: ');
readln(number);
if (number > 0) then
positive := positive + number;
if (number < 0) then
negative := negative * number;
end;
writeln('Positive sum: ',positive);
writeln('Negative mul: ',negative);
if (positive > negative) then
writeln('Sum of positive numbers bigger than mul of negative numbers.')
else if (positive < negative) then
writeln('Sum of positive numbers lesser than mul of negative numbers.')
else
writeln('Sum of positive numbers and mul of negative numbers are equal.');
readln;
end.
Третья задача (проверил, работает):
const N = 10;
var number, lastneg, prevneg, i : integer;
begin
lastneg := 100; prevneg := 100;
for i := 1 to N do
begin
write('Input number: ');
readln(number);
if (number < 0) then
if (lastneg > 0) then
lastneg := number
else
begin
prevneg := lastneg;
lastneg := number;
end;
end;
if (prevneg > 0) then
writeln('This sequence of numbers contains less than two negative numbers.')
else
writeln('Penultimate negative number: ',prevneg);
readln;
end.
1 Задача
n, pr, i, a: integer;
begin
readln(n);
pr := 0;
for i := 1 to n do
begin
read(a);
if (a mod 3 = 0) then
if (pr > 0) then
pr := pr * a
else
pr := a;
end;
writeln(pr);
end.
2 Задача
var
n, i, pl, ot, a: integer;
begin
readln(n);
pl := 0;
ot := 0;
for i := 1 to n do
begin
read(a);
if (a >= 0) then
inc(pl, a)
else
begin
if (ot <> 0) then
ot := ot * a
else
ot := a;
end;
end;
if (pl > ot) then
writeln('Polozitelnii)
else
writeln('Otricat');
end.
var
n, i, a, posl, prd: integer;
begin
readln(n);
posl := 0;
prd := 0;
for i := 1 to n do
begin
read(a);
if (a < 0) then
begin
prd := posl;
posl := a;
end;
end;
if (posl = 0) then
writeln('Нет отрицательных')
else
writeln(prd);
end.