<< pages

fib.c

Last Updated: 25 Feb 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. 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

Source Code

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

Download file icon

Download Source

Download for MS-DOS

Linux Binary

Windows Binary

(C) SOFTWAVE 2026