Computes Fibonacci numbers using a recursive algorithm with optimizations for even/odd indices. Supports interactive input, command-line arguments, and optional timing of computation.
Make sure you have GHC (Glasgow Haskell Compiler) installed.
cd fibonacci
ghc fibonacci.hs -o fibonacci
./fibonacci # Linux/macOS
.\fibonacci.exe # Windows
--print
— prints the Fibonacci number[n]
— optional number argument; if not provided, program prompts for inputExample run:
./fibonacci --print 50 # Linux/macOS
.\fibonacci.exe --print 50 # Windows
Or interactively:
./fibonacci --print
Enter n: 50
The program prints the Fibonacci number and computation time.
Example:
F(50) = 12586269025
Elapsed time: 0.000123 sec
1e3
), and hexadecimal (e.g., 0xFF
) inputs.This project is licensed under the MIT License.