Computer Science, asked by jaspreetkaur10072001, 3 months ago

Write a multithreaded program that generates the Fibonacci sequence. This program should work as follows: On the command line, the user will enter the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers, placing the sequence in data that can be shared by the threads (an array is probably the most convenient data structure). When the thread finishes execution, the parent thread will output the sequence generated by the child thread. Because the parent thread cannot begin outputting the Fibonacci sequence until the child thread finishes, the parent thread will have to wait for the child thread to finish. ​

Answers

Answered by freedarajesh2003
0

In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function. In this program we use recursion to generate the fibonacci series. The function fibonacci is called recursively until we get the output.

Fibonacci Series Algorithm:

Start.

Declare variables i, a,b , show.

Initialize the variables, a=0, b=1, and show =0.

Enter the number of terms of Fibonacci series to be printed.

Print First two terms of series.

Use loop for the following steps. -> show=a+b. -> a=b. -> b=show. -> increase value of i each time by 1. -> print the value of show.

End.

It appears in biological settings such as branching in trees, phyllotaxis (the arrangement of leaves on a stem), the fruit sprouts of a pineapple, the flowering of an artichoke, an uncurling fern and the arrangement of a pine cone's bracts etc. At present Fibonacci numbers plays very important role in coding theory.

This sequence of numbers is called the Fibonacci Numbers or Fibonacci Sequence. The Fibonacci numbers are interesting in that they occur throughout both nature and art. ... Remember that the formula to find the nth term of the sequence (denoted by F[n]) is F[n-1] + F[n-2].

Similar questions