Difference between revisions of "Leonardo number/ru"

From Free Pascal wiki
Jump to navigationJump to search
(Created page with "{{Leonardo_number}} = Числа Leonardo = Числа Leonardo задаются следующей последовательностью: 1, 1, 3, 5, 9, 15, 25 ... ==...")
 
m (Fixed syntax highlighting)
 
Line 6: Line 6:
  
 
  1, 1, 3, 5, 9, 15, 25 ...
 
  1, 1, 3, 5, 9, 15, 25 ...
 
  
 
== Рекурсивный способ ==
 
== Рекурсивный способ ==
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
 
 
function LeonardoNumber( n : integer ):integer;
 
function LeonardoNumber( n : integer ):integer;
 
begin
 
begin
Line 17: Line 15:
 
     else result := 1;
 
     else result := 1;
 
end;   
 
end;   
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 23: Line 20:
 
== Вычисление с помощью [[Fibonacci number/ru|чисел Fibonacci]] ==
 
== Вычисление с помощью [[Fibonacci number/ru|чисел Fibonacci]] ==
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
 
 
function LeonardoNumber2( n : integer ):integer;
 
function LeonardoNumber2( n : integer ):integer;
 
begin
 
begin
 
   result := 2 * FibonacciNumber( n + 1) - 1
 
   result := 2 * FibonacciNumber( n + 1) - 1
 
end;
 
end;
 
 
</syntaxhighlight>
 
</syntaxhighlight>
<br>
 

Latest revision as of 02:32, 19 February 2020

Deutsch (de) English (en) suomi (fi) français (fr) русский (ru)

Числа Leonardo

Числа Leonardo задаются следующей последовательностью:

1, 1, 3, 5, 9, 15, 25 ...

Рекурсивный способ

function LeonardoNumber( n : integer ):integer;
begin
  if n > 1 then result := LeonardoNumber( n - 1 ) + LeonardoNumber( n - 2 ) + 1
    else result := 1;
end;


Вычисление с помощью чисел Fibonacci

function LeonardoNumber2( n : integer ):integer;
begin
  result := 2 * FibonacciNumber( n + 1) - 1
end;