add: for sample, fix bugs, and make test harness
This commit is contained in:
27
samples/fib.rpg
Normal file
27
samples/fib.rpg
Normal file
@@ -0,0 +1,27 @@
|
||||
**FREE
|
||||
Ctl-Opt Main(Perform_Fibonacci_Sequence);
|
||||
|
||||
Dcl-Proc Perform_Fibonacci_Sequence;
|
||||
|
||||
Dcl-s i Uns(10);
|
||||
Dcl-s fib Uns(10) Dim(10);
|
||||
|
||||
// Display a title
|
||||
Dsply ('Fibonacci Sequence:');
|
||||
|
||||
// Initialize the first two elements of the array
|
||||
fib(1) = 0; // The sequence usually starts with 0 and 1
|
||||
fib(2) = 1;
|
||||
|
||||
// Loop to calculate the rest of the sequence
|
||||
For i = 3 to %Elem(fib);
|
||||
// Each number is the sum of the two preceding ones
|
||||
fib(i) = fib(i-1) + fib(i-2);
|
||||
Endfor;
|
||||
|
||||
// Loop to display the sequence numbers
|
||||
For i = 1 to %Elem(fib);
|
||||
Dsply (' ' + %Char(fib(i)));
|
||||
Endfor;
|
||||
|
||||
End-Proc Perform_Fibonacci_Sequence;
|
||||
Reference in New Issue
Block a user