Deliverable For each of the problems shown below, clearly define what the output
ID: 3854374 • Letter: D
Question
Deliverable
For each of the problems shown below, clearly define what the output, input and processing tasks should be to meet the requirements you have been given.
Upload your homework file as a .pdf file to Canvas before the due date specified on Canvas. Late homework will not be accepted.
PROBLEMS
(10 pts) A program determines the position n of a particular number in the Fibonacci sequence. Fibonacci numbers Fn are defined by the recursive relation[1] below. It is assumed that the Fn provided is a valid Fibonacci number.
where the initial seeds are F0 = 0 and F1 = 1. The following table shows the position n of the first six numbers Fn in the Fibonacci sequence (including the seeds 0 and 1);
Position (n)
0
1
2
3
4
5
Fibonacci number (Fn)
0
1
1
2
3
5
The formula to calculate the position n of a Fibonacci number Fn in the Fibonacci sequence is:
is the golden ratio.
Equation (1) will be evaluated twice (i.e., once with +4, and once with -4) and only integer solutions can be used to represent the position n of a Fibonacci number Fn. (Hint: The logarithm change-of-base formula can help simplify complicated logarithm functions.)
[1] https://en.wikipedia.org/wiki/Fibonacci_number
Position (n)
0
1
2
3
4
5
Fibonacci number (Fn)
0
1
1
2
3
5
A program determines the position n of a particular number in the Fibonacci sequence. Fibonacci numbers Fn are defined by the recursive relation[1] below. It is assumed that the Fn provided is a valid Fibonacci number. where the initial seeds are F_0 = 0 and F_1 = 1. The following table shows the position n of the first six numbers F_n in the Fibonacci sequence (including the seeds 0 and 1): The formula to calculate the position n of a Fibonacci number F_n in the Fibonacci sequence is: n = log_phi (F_n Squareroot 5 + Squareroot 5 F_n ^2 plusminus 4/2) is the golden ratio. phi = 1 + Squareroot 5/2 almostequalto 1.6180339887 .. Equation (1) will be evaluated twice (i.e., once with +4, and once with -4) and only integer solutions can be used to represent the position n of a Fibonacci number F_n.Explanation / Answer
The program is given below:
#include<stdio.h>
#include<math.h>
int position(int f)//function to calculate position
{
float phi=(1+sqrt(5))/2;//golden number
float x1=(f*sqrt(5)+sqrt(5*f*f+4))/2;
float x2=(f*sqrt(5)+sqrt(5*f*f-4))/2;
float p1,p2;
p1=log(x1)/log(phi);//Equation evaluated using +4
p2=log(x2)/log(phi);//Equation evaluated using -4
return (p1==ceil(p1)?p1:p2);//returning the integer of the two values
}
void main()
{
int f;
printf("Enter the Fibonacci number:");
scanf("%d",&f);//Fn is entered
printf("The position of %d is %d",f,position(f));//Position of Fn is printed using the function
}
A sample output for this program is given below:
Enter the Fibonacci number:13
The position of 13 is 7
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.