The Fibonacci Series is one of the most famous sequences in mathematics and computer science. In this series, every number is the sum of the two numbers before it. Starting from 0 and 1:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
The Fibonacci sequence appears throughout nature โ in the spiral arrangement of a sunflower's seeds, the pattern of a pine cone, the branching of trees, and the spiral shell of the nautilus. This is sometimes called the 'fingerprint of nature'.
#include <stdio.h>
int main() {
int n, a = 0, b = 1, c;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (int i = 1; i <= n; i++) {
printf("%d ", a);
c = a + b; // next term = sum of previous two
a = b; // update a
b = c; // update b
}
return 0;
}
Output for n=8: 0 1 1 2 3 5 8 13
#include <stdio.h>
int fibonacci(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fibonacci(n-1) + fibonacci(n-2);
}
int main() {
int n;
printf("Enter terms: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
printf("%d ", fibonacci(i));
}
return 0;
}
Note: The iterative method is much more efficient. The recursive method has O(2โฟ) time complexity (exponential โ very slow for large n), while the iterative method is O(n) (linear โ much faster).
Starting from the 1st term as 0: 0, 1, 1, 2, 3, 5, 8, 13, 21, **34**. The 10th term is **34**.
What is the Full Form of ITES?
Learn the full form of ITES in the computer and business world. Understand what Information Technology Enabled Services means, including BPOs and Call Centers.
What is the Full Form of ITS? (Technology)
Learn the full form of ITS. Understand what an Intelligent Transportation System is and how it uses massive AI and GPS to control smart city traffic.
What is Junk Email Also Called?
Learn the most common massive name for Junk Email. Understand what SPAM is, how scammers use it, and how massive email filters protect your inbox.
Difference Between LAN, MAN, and WAN
Learn the massive technical difference between LAN, MAN, and WAN in computer networking. Understand coverage areas, heavy speeds, and massive examples.
MAN Full Form in Computer Networks
Find the full form of MAN in computer networking. Understand the difference between LAN, MAN, and WAN, and see examples of a Metropolitan Area Network.
Turn this guide into revision flashcards, a practice exam, or an AI-generated podcast โ free, no signup required.