Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

What is the Fibonacci Sequence?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Fibonacci numbers, commonly denoted as F(n), form a sequence called the Fibonacci Sequence. Each number in the Fibonacci series is the sum of the two preceding ones, starting from 0 and 1. The formula to compute the sequence is as follows:

Fn=Fn1+Fn2F_{n}=F_{n-1}+F_{n-2}

The slideshow below illustrates the concept:

1 of 6

From a coding perspective, an iterative approach to solving the Fibonacci sequence is given below:

int main(){
int num = 8;
int element1 = 0, element2 = 1, next = 0;
for (int i = 1 ; i < num ; i++ )
{
if ( i <= 1 )
next = i;
else{
next = element1 + element2;
element1 = element2;
element2 = next;
}
cout << "Adding " << element1 << " and " << next << " = " << element2+element1 << endl;
}
}

RELATED TAGS

Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring