Answer to Question #21318 in C++ for George

Question #21318
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.
1
Expert's answer
2013-01-08T11:53:18-0500
//& Defines the entry point for the console application.

#include "stdafx.h"
#include "iostream"
#include "process.h"
#include "windows.h"
#include "vector"

using namespace std;
int q = 40;
HANDLE thread;

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

if (n <= 2)
{
dp.push_back(1);
return dp;
}

dp[1] = 1;
dp[2] = 1;
for (int i = 3; i <= n; i++)
{
dp[i] = dp[i - 1] + dp[i - 2];
}

for(int i = 0;i<n;i++)
{
cout<<dp[i]<<endl;
}
return dp;
}

DWORD WINAPI runer(LPVOID lpParam)
{
fibonachi(q);
return NULL;
}

int _tmain(int argc, _TCHAR* argv[])
{
DWORD task_id;

thread = CreateThread(0,0,runer,NULL,0,&task_id);
WaitForSingleObject(thread, INFINITE);

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
09.01.13, 14:17

You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!

george
08.01.13, 19:30

thank you very much

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS