add: fib sample

This commit is contained in:
2026-03-12 22:19:42 -07:00
parent 073c86d784
commit 31a6c8b91b
7 changed files with 756 additions and 46 deletions

27
fib.rpg Normal file
View 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;