pacixor8) var f_tmp, f1, f, sum: integer; i, n: byte; begin readln(n); f_tmp := 0; f1 := 1; if n = 0 then sum := 0 else sum := 1; for i := 2 to n do begin f := f1 + f_tmp; sum := sum + f; f_tmp := f1; f1 := f end; writeln('Сумма ', n , ' чисел = ',sum); readln; end.
9) const n = 5; var A: array [1 .. 10, 1 .. 10] of integer; i, j, s, w, k, q: integer; begin for i := 1 to n do for j := 1 to n do begin write('A[', j, ',', i, '] = '); readln(A[j, i]); end; s := 0; for i := 1 to n do s := s + A[1, i]; k := 1; for i := 1 to n do begin w := 0; q := 0; for j := 1 to n do begin w := w + A[j, i]; q := q + A[i, j]; end; if (s <> w) or (q <> s) then k := 0; end; if k = 0 then write('Квадрат не магический') else write('Квадрат магический'); readln; end.
Answers & Comments
var
f_tmp, f1, f, sum: integer;
i, n: byte;
begin
readln(n);
f_tmp := 0;
f1 := 1;
if n = 0 then sum := 0
else sum := 1;
for i := 2 to n do
begin
f := f1 + f_tmp;
sum := sum + f;
f_tmp := f1;
f1 := f
end;
writeln('Сумма ', n , ' чисел = ',sum);
readln;
end.
9)
const n = 5;
var
A: array [1 .. 10, 1 .. 10] of integer;
i, j, s, w, k, q: integer;
begin
for i := 1 to n do
for j := 1 to n do
begin
write('A[', j, ',', i, '] = ');
readln(A[j, i]);
end;
s := 0;
for i := 1 to n do s := s + A[1, i];
k := 1;
for i := 1 to n do
begin
w := 0; q := 0;
for j := 1 to n do
begin
w := w + A[j, i];
q := q + A[i, j];
end;
if (s <> w) or (q <> s) then
k := 0;
end;
if k = 0 then write('Квадрат не магический')
else write('Квадрат магический');
readln;
end.