
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C/C++ Program for the n-th Fibonacci number?
The Fibonacci sequence is a series where the next term is the sum of the previous two terms.The first two terms of the Fibonacci sequence is 0 followed by 1.
In this problem, we will find the nth number in the Fibonacci series. For this we will calculate all the numbers and print the n terms.
Input:8 Output:0 1 1 2 3 5 8 13
Explanation
0+1=1 1+1=2 1+2=3 2+3=5
Using For loop to sum of previous two terms for next term
Example
#include<iostream> using namespace std; int main() { int t1=0,t2=1,n,i,nextTerm; n = 8; for ( i = 1; i <= n; ++i) { if(i == 1) { cout << " " << t1 ; continue; } if(i == 2) { cout << " " << t2 << " " ; continue; } nextTerm = t1 + t2 ; t1 = t2 ; t2 = nextTerm ; cout << nextTerm << " "; } }
Output
0 1 1 2 3 5 8 13
- Related Articles
- Python Program for n-th Fibonacci number
- Java Program for n-th Fibonacci number
- N-th Fibonacci number in Python Program
- C Program for n-th even number
- C Program for n-th odd number
- C program to find Fibonacci series for a given number
- An efficient way to check whether n-th Fibonacci number is multiple of 10?
- C++ Program for Area Of Square after N-th fold
- C Program for N-th term of Geometric Progression series
- C Program for N-th term of Arithmetic Progression series
- N-th Tribonacci Number in C++
- N-th polite number in C++
- Program for Fibonacci numbers in C
- Java Program for check if a given number is Fibonacci number?
- C++ program to find Nth Non Fibonacci Number

Advertisements