# Answer to Question #21406 in C++ for george

Question #21406

Create a thread that will use a runner function and from the thread function (e.g. runner) call the Fibonacci function to generate the Fibonacci series and store them in the array. Use the parameter supplied in the function runner in order to determine how many Fibonacci numbers must be generated.

Expert's answer

# include <iostream>

#include <vector>

using namespace std;

//returns

std::vector<int> fib_n(int n)

{

std::vector<int> dp(n + 1);

dp[1] = 1;

if (n<2) return dp;

dp[2] = 1;

if (n<3) return dp;

for (int i = 3; i <= n; i++)

{

dp[i] = dp[i - 1] + dp[i - 2];

}

return dp;

}

void print (vector<int> a){

for(int i=1;i<a.size();i++){

cout<<a[i]<<" ";

}

}

int main(){

setlocale( LC_ALL,"Russian" );

vector<int> c;

int n;

cout<<"Enter n : ";

cin>>n;

c=fib_n(n);

print(c);

system("PAUSE");

return 0;

}

## Comments

## Leave a comment