🔀Beginner

Print Fibonacci Series

Print Fibonacci sequence

The Fibonacci sequence is a series where each number is the sum of the two preceding ones.
Starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Formula: F(n) = F(n-1) + F(n-2)

🔢 Fibonacci Pattern

0
+
1
+
1
+
2
+
3
+
5
+
8
+
13
+
21
+
34
...

Each number = previous two numbers added together

C Program to Print Fibonacci Series

fibonacci.c
C
1#include <stdio.h>
2
3int main() {
4 int n;
5 int first = 0, second = 1, next;
6
7 printf("Enter number of terms: ");
8 scanf("%d", &n);
9
10 printf("Fibonacci Series: ");
11
12 for (int i = 0; i < n; i++) {
13 printf("%d ", first);
14
15 // Calculate next term
16 next = first + second;
17 first = second;
18 second = next;
19 }
20
21 printf("\n");
22 return 0;
23}
Output

Enter number of terms: 10

Fibonacci Series: 0 1 1 2 3 5 8 13 21 34

How the Loop Works

ifirstsecondOutputnext
00101
11112
21213
32325
43538

🌍 Real-World Applications

  • Nature: Spiral patterns in shells, sunflower seeds
  • Art: Golden ratio in design and architecture
  • Computer Science: Algorithm analysis, data structures

📝 Key Takeaways

F(n) = F(n-1) + F(n-2)
Starts with 0 and 1
Use 3 variables to track sequence
Can also be done with recursion