var n: integer;function fibonachi(n: integer): integer;begin if (n = 1) or (n = 2) then fibonachi := 1 else fibonachi:= fibonachi(n - 1) + fibonachi(n - 2);end;begin read(n); writeln('F(', n, ') = ', fibonachi(n));end.
------------------------------------------------------
var n, i: integer; a: array [1..3] of longint;begin read(n); a[2] := 1; a[3] := 1; for i := 3 to n do begin a[1] := a[2]; a[2] := a[3]; a[3] := a[2] + a[1]; end; writeln('F(', n, ') = ', a[3]);end.
var a1,a2, n, i:integer;begin
a1 := 1;
a2 := 1; write('n = '); readln(n);
for i := 2 to n - 1 do
begin
a1 := a1 + a2;
a2 := a1 - a2;
end;
writeln(n, ' элемент последовательности Фибоначчи равен ', a1);
end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
var
n: integer;
function fibonachi(n: integer): integer;
begin
if (n = 1) or (n = 2) then fibonachi := 1
else fibonachi:= fibonachi(n - 1) + fibonachi(n - 2);
end;
begin
read(n);
writeln('F(', n, ') = ', fibonachi(n));
end.
------------------------------------------------------
var
n, i: integer;
a: array [1..3] of longint;
begin
read(n);
a[2] := 1;
a[3] := 1;
for i := 3 to n do
begin
a[1] := a[2];
a[2] := a[3];
a[3] := a[2] + a[1];
end;
writeln('F(', n, ') = ', a[3]);
end.
Verified answer
var
a1,a2, n, i:integer;
begin
a1 := 1;
a2 := 1;
write('n = '); readln(n);
for i := 2 to n - 1 do
begin
a1 := a1 + a2;
a2 := a1 - a2;
end;
writeln(n, ' элемент последовательности Фибоначчи равен ', a1);
end.