Virtual Object
::
Programs
::
Генерация n-ого числа Фибоначчи |
||||
Наша кнопка |
||||
Генерация n-ого числа Фибоначчи {$APPTYPE CONSOLE} var a,b,c:array [1..1000] of integer; i,j,n,la,lb,lc:integer; function summ(la,lb:integer):integer; var i,max:integer; begin max:=la; if (lb > la) then max:=lb; for i:=1 to max do begin c[i]:=c[i] + a[i] + b[i]; c[i+1]:=c[i] div 10; c[i]:=c[i] mod 10; end; if (c[max+1]<>0) then summ:=max+1 else summ:=max; end; begin assign(input,′input.txt′); reset(input); assign(output,′output.txt′); rewrite(output); read(n); {f0=1 f1=1} a[1]:=1; b[1]:=1; la:=1; lb:=1; while n>1 do begin lc:=summ(la,lb); for j:=1 to lb do a[j]:=b[j]; la:=lb; for j:=1 to lc do b[j]:=c[j]; lb:=lc; fillchar(c,sizeof(c),0); dec(n); end; for i:=lb downto 1 do write(b[i]); end. |
||||
Object © 2004 - 2005. All rights reserved. |