Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dark mode QB64-PE IDE colors themes
#4
Just a simple example of including programs in other languages in Basic. The Fibonacci number.
Of course, it would be easier to catch the return value for input that is too large in Basic, but it's just an exercise.

The damn Timer isn't working or it's going too fast. . .

The C-Code:
Code: (Select All)
#include <stdio.h>
#include <stdlib.h>

long fibo(int n)
{
    long x, y;
    int i;
    
    x = y = i = 1;
    if (n == 0 || n == 1)
    {
        return(n);
    }    
    if (n > 40)
    {
        return(-1);
        //sonst Überlauf
    }
    else while (i < n)
    {
        x = x + y; y = x - y; i++;        
    }
    return(x);
}
The Basic-Code:
Code: (Select All)
Option _Explicit

'In QB64 mit "Declare Library" wie angegeben
Declare Library "D:\Lab\QuickBasic64\Extern-nicht-Basic\bfibonacci"
  Function fibo& (ByVal N As Integer)
End Declare

Dim As Integer N, rueckgabe
Dim As Single zeitstart, zeitende

Timer On

Cls
Locate 3, 3
Input "Berechnet die Fibonacci-Zahl von: ", N

zeitstart = Timer

Locate 5, 3
rueckgabe = fibo&(N%)
If rueckgabe = -1 Then
  Print "Eingabe zu gross!"
  Sleep: System
Else
  Print Using "Die Fibonacci-Zahl von ## = ###,########"; N; fibo&(N%)
End If

zeitende = Timer

Locate 7, 3
Print Using "Sekunden: ##.#### "; zeitende - zeitstart

End
Reply


Messages In This Thread
Dark mode QB64-PE IDE colors themes - by a740g - 06-29-2023, 09:05 PM
RE: Dark mode QB64-PE IDE colors themes - by Kernelpanic - 06-30-2023, 01:44 AM



Users browsing this thread: 2 Guest(s)