Question

Using the C Language - Calculate and print the first 20 elements of the Fibonacci series....

Using the C Language -

Calculate and print the first 20 elements of the Fibonacci series. You must use the recursive function call method to calculate the elements.

Output the elements of the series in a fixed column width table format and calculate Phi for each step.

Output how many iterations it would take to approach the theoretical value of Phi within 0.1%.

For example:

N    Fibonacci Phi

--------------------------------------------------

1 0    N/A

2    1    N/A

3 1 1.0

4 2 2.0

5    3    1.5

….

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program

#include<stdio.h>

//recursive function to calculate the Fibonacci series.
int fibo(int n)
{
if(n==0 || n==1)
return n;
return fibo(n-1) + fibo(n-2);
}
//function to calculate Phi
float getPhi(int i)
{
return (float)fibo(i)/fibo(i-1);
}

//main function

int main()
{
int i = 0;

printf("N\tFibonacci\tPhi\n");
printf("--------------------------------------\n");
printf("%d\t%d\t\tN/A\n", ++i, fibo(i));
printf("%d\t%d\t\tN/A\n", ++i, fibo(i));

for(i=2; i<20; i++)
{
printf("%d\t%d\t\t%f\n", i+1, fibo(i), getPhi(i));
}

return 0;
}

Output

Add a comment
Know the answer?
Add Answer to:
Using the C Language - Calculate and print the first 20 elements of the Fibonacci series....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an ARM assembly language subroutine (named nfibo) to calculate and return the n-th Fibonacci number....

    Write an ARM assembly language subroutine (named nfibo) to calculate and return the n-th Fibonacci number. Fibonacci numbers (or a Fibonacci sequence) are a series of numbers with a property that the next number in the series is a sum of previous two numbers. Starting the series from 0, 1 as the first two numbers we have 0, 1, (0 + 1) = 1, (1 + 1) = 2, (1 + 2) = 3, (2 + 3) = 5, (3...

  • in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5,...

    in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89.. 1 See the pattern? Each element in the series is the sum of the preceding two items. There is a recursive formula for calculating the nth number of the sequence (the oth number if Fib(0)-0): 8 Fib(N)-/N, if N 0 or 1 ifN> 1 Fib(N-2) Fib(N-1), a. b. c. Write a recursive version of the function Fibonacci. Write...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8,...

    c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21 Note that the first Fibonacci number is 1, F(1) = 1 The second Fibonacci number is 1, i.e. F(2) = 1 Other Fibonacci numbers in the sequence is the sum of two previous Fibonacci numbers. For example F(3) = F(2) + F(1). In general F(n) = F(n-1) + F(n-2) Write a program to do the following tasks. User entries are shown in...

  • Solve using C language The mathematician Euler proved that: tan-(x) = x -. Write a C...

    Solve using C language The mathematician Euler proved that: tan-(x) = x -. Write a C program to do the following: -Ask user to enter the value of (x) radians, -0.5<=x<=0.5. -Calculate and print the actual value atan (x)in degrees. - Use loops to calculate and print the series sum in degrees. -loop should stop when absolute difference between actual and series sum become <=10-3. -Print out number of iterations needed to get the result. - The program should run...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • using C language Create an array of doubles with 5 elements. In the array prompt the...

    using C language Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...

  • Write common assembly language (RISC) programs to a) sum the first n elements of an array...

    Write common assembly language (RISC) programs to a) sum the first n elements of an array A, and b) compute r = ab for unsigned integers a and b. Each program will consist of a driver and a subprogram. The drivers will 1) read one or more values from the keyboard, 2) call the subprogram, and 3) print a result. The subprograms must not: ● store into memory, ● use registers $1 – $9, or ● make system calls

  • C Language Question

    Write a program to calculate the row averages of a 4x4 matrix. In main program get the elements of a 4x4 matrix and display the matrix, then call the function “average” to calculate the row averages. Function “average” will find the average of rows of a 4x4 matrix and store the results into a 1-dimensional array and return it as parameter. Main program should display the row averages which are greater than 5.0 returned by the function “average”. Use c language  Enter...

  • Coding in C# please Develop the C# program for the following problems: 1. Create a new...

    Coding in C# please Develop the C# program for the following problems: 1. Create a new class and name it as Conversion. 2. In this class, provide the code that uses a for or while loop to display a table that lists values for some unit and the equivalent in two other units. . Enter a start value, and end value and a step value as a range of values for the unit to be converted, . Show three columns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT