How to resolve the algorithm Leonardo numbers step by step in the FutureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Leonardo numbers step by step in the FutureBasic programming language
Table of Contents
Problem Statement
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
This task will be using the 3rd equation (above) to calculate the Leonardo numbers.
Edsger W. Dijkstra used Leonardo numbers as an integral part of his smoothsort algorithm.
The first few Leonardo numbers are:
(The last task requirement will produce the Fibonacci numbers.)
Show all output here on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Leonardo numbers step by step in the FutureBasic programming language
Source code in the futurebasic programming language
local fn LeoFiboNumbers( number as long, l0 as long, l1 as long, sum as long ) as CFArrayRef
long i, tmp
CFMutableArrayRef mutArr = fn MutableArrayWithCapacity(0)
for i = 1 to number
if i = 1
MutableArrayAddObject( mutArr, fn StringWithFormat( @"%ld", l0 ) )
else
if i = 2
MutableArrayAddObject( mutArr, fn StringWithFormat( @"%ld", l1 ) )
else
MutableArrayAddObject( mutArr, fn StringWithFormat( @"%ld", l0 + l1 + sum ) )
tmp = L0 : l0 = l1 : l1 = tmp + l1 + sum
end if
end if
next
end fn = mutArr
void local fn CompareResults( number as long )
CFArrayRef leonardoArr = fn LeoFiboNumbers( number, 1, 1, 1 )
CFArrayRef fibonacciArr = fn LeoFiboNumbers( number, 0, 1, 0 )
long i, count = fn ArrayCount( leonardoArr )
printf @"First %ld numbers of:\n%8s%11s", number, fn StringUTF8String( @"Leonardo" ), fn StringUTF8String( @"Fibonacci" )
for i = 0 to count - 1
printf @"%8s%11s", fn StringUTF8String( leonardoArr[i] ), fn StringUTF8String( fibonacciArr[i] )
next
end fn
fn CompareResults( 35 )
HandleEvents
You may also check:How to resolve the algorithm A+B step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Factorial step by step in the Lingo programming language
You may also check:How to resolve the algorithm Long literals, with continuations step by step in the 6502 Assembly programming language