Computer Science & C Programming

You must DEPOSIT your source code, named your-name.c, with the link placed at the bottom of this page (also add your mail address and date as a comment in the source file)

Golden Ratio

  1. Define a program to compute f(x) such as f(0)=1, f(1)=1, and f(n)=f(n-1)+f(n-2).
    To proceed, represent and encode the following algorithm:
    i=n, a=1, b=1, loop: c=a+b, a=b, b=c, i=i-1, goto loop if (i!=0)
    Use successively: goto, while and for loops.
    What is the value of f(10) ?
    Nb. This program computes Fibonacci numbers.

  2. Define a program that fill an array t with t[0]=1, t[1]=1, t[n]=t[n-1]+t[n-2].
    Discuss the benefit/disadvantage of using t rather than f to compute a particular value of n.

  1. For which value of n, the value of f(n) becomes "inconsistent" ?
    Explain why and which datatype can be used to improve that ?

  2. What is the limit of f(n+1)/f(n) when n tends to the preceding value ?

  3. By using the bissection method, find which number n must be added to 1 to get its square (ie. solve x^2=x+1) ?
    Nb. Interval to be considered is [1,3] and a precision of 0.00001.

  4. Write a program to compute s=1+1/(1+1/(1+1/(1+1/(...))))
    How many loops must be performed to get the precision is 0.00001 ?

  5. Check that values of questions 4, 5 and 6 are the same; this value is called "golden ratio"