This C program prints out the first Fibonacci series (sequence) of N numbers. In mathematics, the Fibonacci numbers are a sequence of numbers named after Leonardo of Pisa, known as Fibonacci. The first number of the sequence is 0, the second number is 1, and each subsequent number is equal to the sum of the previous two numbers of the sequence itself, thus creating the sequence 0, 1, 1, 2, 3, 5, 8, etc. The standard form of writing Fibonacci series is:
xn = xn-1 + xn-2
where:
- xn is term number “n”
- xn-1 is the previous term (n-1)
- xn-2 is the term before that (n-2)

So this program prints the N numbers of Fibonacci series in C on the screen where N is the integer number entered by the user. This C program prints maximum of 50 Fibonacci numbers.
This program uses the following C Programming topics so go thorough these articles for a better understanding of the program:

Kickstart your coding journey with Beginning C++23 – the ultimate guide to mastering the latest in modern C++ programming!
View on Amazon
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdio.h> int main(void) { //The number of Fibonacci numbers we will print int n; // The index of Fibonacci number to be printed next int i; // The value of the (i)th Fibonacci number long current; // The value of the (i+1)th Fibonacci number long next; // The value of the (i+2)th Fibonacci number long twoaway; printf("How many Fibonacci numbers do you want to compute? \n"); scanf("%d", &n); if (n<=0 || n>50 ) { printf("The number should be positive and less than 51.\n"); } else { printf("\n\n\tI \t Fibonacci(I) \n\t=====================\n"); next = current = 1; for (i=1; i<=n; i++) { printf("\t%d \t %ld\n", i, current); twoaway = current+next; current = next; next = twoaway; } } } |
Output of the C Program
1 | How many Fibonacci numbers do you want to compute? <br>50<br> I Fibonacci(I) <br> =====================<br> 1 1<br> 2 1<br> 3 2<br> 4 3<br> 5 5<br> 6 8<br> 7 13<br> 8 21<br> 9 34<br> 10 55<br> 11 89<br> 12 144<br> 13 233<br> 14 377<br> 15 610<br> 16 987<br> 17 1597<br> 18 2584<br> 19 4181<br> 20 6765<br> 21 10946<br> 22 17711<br> 23 28657<br> 24 46368<br> 25 75025<br> 26 121393<br> 27 196418<br> 28 317811<br> 29 514229<br> 30 832040<br> 31 1346269<br> 32 2178309<br> 33 3524578<br> 34 5702887<br> 35 9227465<br> 36 14930352<br> 37 24157817<br> 38 39088169<br> 39 63245986<br> 40 102334155<br> 41 165580141<br> 42 267914296<br> 43 433494437<br> 44 701408733<br> 45 1134903170<br> 46 1836311903<br> 47 2971215073<br> 48 4807526976<br> 49 7778742049<br> 50 12586269025 |