uses crt; function f(n:longint):longint; begin if(n>0)and(n<=2)then f:=1 else f:=f(n-1)+f(n-2); end; begin clrscr; writeln(f(3)); readln end.
Nhập:
uses crt; var n:longint; function f(n:longint):longint; begin if(n>0)and(n<=2)then f:=1 else f:=f(n-1)+f(n-2); end; begin clrscr; write(‘Nhap so: ‘); readln(n); writeln(f(n)); readln end.
var n:integer;
function f(i:integer):integer;
begin
if i <= 2 then f := 1
else f := f(i-1) + f(i-2);
end;
begin
n:=4;
writeln(f(n));
end.
@danhle
Gán (lấy số 3 nhé):
uses crt;
function f(n:longint):longint;
begin
if(n>0)and(n<=2)then f:=1
else f:=f(n-1)+f(n-2);
end;
begin
clrscr;
writeln(f(3));
readln
end.
Nhập:
uses crt;
var n:longint;
function f(n:longint):longint;
begin
if(n>0)and(n<=2)then f:=1
else f:=f(n-1)+f(n-2);
end;
begin
clrscr;
write(‘Nhap so: ‘); readln(n);
writeln(f(n));
readln
end.