Fibonacci Number C++

Fibonacci number is a sequence of number. It also called as Fibonacci series or Fibonacci Sequence. The following numbers is hte fibonacci number:

1,1,2,3,5,8,13,21,34,55,89,144,.....
or
0,1,1,2,3,5,8,13,21,34,55,89,144,.......

By definition, the first two numbers in the Fibonacci sequence are 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.


#include <iostream>
using namespace std;

int fib (int x) {
if (x==0) return 0;
else if(x==1) return 1;
else return fib(x-1)+fib(x-2);
}
int fib (int x) {
if (x==0) return 0;
else if(x==1) return 1;
else return fib(x-1)+fib(x-2);
}

int main(){
for(int i=0;i<=10;i++){
cout<<fib(i)<<endl;
}
return 0;
}


Comments

Popular posts from this blog

Reading and Writing Operation of SRAM

Reading & Writing Operation of DRAM

Method to Convert from Stream to Json C#