- Code: Select all Expand view RUN
- function Main()
local n
for n = 0 to 25
? fibonacci( n )
next
return nil
function fibonacci( n )
if n <= 1
return 1
endif
return fibonacci( n - 1 ) + fibonacci( n - 2 )
function Main()
local n
for n = 0 to 25
? fibonacci( n )
next
return nil
function fibonacci( n )
if n <= 1
return 1
endif
return fibonacci( n - 1 ) + fibonacci( n - 2 )
#include "FiveWin.ch"
function Main()
local n, nStart, nDelay, nFibonacci
set decimal to 8
nStart := Seconds()
n = 32
nFibonacci := C_FIBONACCI( n )
nDelay := Seconds() - nStart
? "n, Fibonacci, delay = ", n, nFibonacci, nDelay
RETURN nil
//--------------------------------------
// C function
//-------------------------------------
#pragma BEGINDUMP
#include <hbapi.h>
#include <math.h>
long long C_FIBONACCI( int n );
HB_FUNC( C_FIBONACCI )
{
int n;
n = hb_parni(1);
if ( n == 0 )
hb_retnll(0);
else if ( n == 1 )
hb_retnll(1);
else
hb_retnll ( C_FIBONACCI(n-1) + C_FIBONACCI(n-2) );
}
#pragma ENDDUMP
#include "FiveWin.ch"
function Main()
local n, nStart, nDelay, nFibonacci
set decimal to 8
nStart := Seconds()
n = 32
nFibonacci := C_FIBONACCI( n )
nDelay := Seconds() - nStart
? "n, Fibonacci, delay = ", n, nFibonacci, nDelay
RETURN nil
//--------------------------------------
// C function
//-------------------------------------
#pragma BEGINDUMP
#include <hbapi.h>
#include <math.h>
long long C_Fibonacci( int n )
{
if ( n == 0 )
return (0);
else if ( n == 1 )
return (1);
else
return ( C_Fibonacci(n-1) + C_Fibonacci(n-2) );
}
HB_FUNC( C_FIBONACCI )
{
int n;
n = hb_parni(1);
hb_retnll ( C_Fibonacci(n) );
}
#pragma ENDDUMP
Return to Utilities / Utilidades
Users browsing this forum: No registered users and 3 guests