<< pages

fib.c file icon

Last Updated: 19 June 2026

fib.c screenshot

One of my most popular YouTube videos is my demonstration of a fast Fibonacci number finder in C. The code is available below and on GitHub. With clever programming (and with GMP -- the GNU Multiple Precision Arithmetic Library, as well as refinements from others), this program can calculate, and print out, Fibonacci numbers with millions of digits in fractions of a second. The algorithm is based on the fast doubling method, which allows us to compute Fibonacci numbers in logarithmic time. Ie: O log n.

The results speak for themselves. The 100 millionth fibonacci number is calculated and printed to standard out in 1.46 seconds on my machine.

This is a number with over 20 million digits, and that if we pipe to a file yeilds us a twenty megabyte text file.

If we search for the five billionth Fibonacci number, we get a number with over 1.04 billion digits. It takes just 1 minute and 56 seconds to calculate and print this almighty number, and the resulting text file is over a full gigabyte in size.

Developed on Linux and cross-compiled to Windows and MS-DOS.

Video Demo file icon

Source Code file icon

Usage file icon

To run: fib <nth Fibonacci number>

To run without timing: fib -p <nth Fibonacci number>

Building file icon

All require GMP.

To build on UNIX: gcc fib.c -o fib -lgmp -O3

To build for Windows on UNIX: fib x86_64-w64-mingw32-gcc fib.c -o fib.exe -lgmp -O3

To build for MS-DOS (djgpp): gcc fibdos.c -o fibdos.exe -lgmp -O3

Download file icon

Download Source

MS-DOS Binary

Linux Binary

Windows Binary

Credits file icon

Uses GMP for arbitrary precision arithmetic.

Originally written by Softwave. Massive speedups by Francesco146. and LizzyFleckenstein03.

More additions then by myself (Softwave).

License: Public Domain/CC0

(C) SOFTWAVE 2026