kikit
6/6/2016 - 2:23 PM

Fibonacci Series

Fibonacci Series

#include <iostream>
using namespace std;

int fibresult[100];

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

void fib_dp(int n){
	fibresult[0] = 1;
	fibresult[1] = 1;
	for(int i=2; i<n; i++){
		fibresult[i] = fibresult[i-1] + fibresult[i-2];
	}
	for(int i=0; i<n; i++){
		cout << fibresult[i] << " " ;
	}
}
int main() {
	// your code goes here
	int n = 10;
	for(int i=0; i<n; i++){
		cout << fib(i) << " ";
	}
	cout<<endl;
	fib_dp(10);
	return 0;
}