Question

Write a program that calculates Fibonacci numbers, as defined in section 2.4, definition 5. Demonstrate your...

Write a program that calculates Fibonacci numbers, as defined in section 2.4, definition 5.

Demonstrate your code by calculating the 3, 5, and 10th Fibonacci numbers.

You should turn in a brief report by the end of class. Your report should include:
• 5 points: Your name
• 20 points:A single question describing what the question is asking
• 10 points:A list of other useful resources and references.
• 10 points:A list of key assumptions and general observations
• 10 points:A copy of your calculations and other work
• 25 points:Your code
• 10 points:Your code output
• 10 points:A discussion of your solution, and why you believe it is correct

Use any language

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

Solution for the above question are as follows -

Code :

#include<stdio.h>
int main()
{
// local variable declaration
int n, i = 0, j;
// get input from user
printf("Enter number : ");
scanf("%d", &n);
// call to Fibonacci function and print the series
printf("Fibonacci series : ");
for (j = 1; j <= n; j++)
{
printf("%d ", fibonacci(i));
i++;
}
return 0;
}
// fibonacci - this function check the n variable value and recursively call to itself and return int value
int fibonacci(int n)
{
if (n < 0)
return 0;
else if (n == 0 || n == 1)
return n;
else
return (fibonacci(n-1) + fibonacci(n-2));
}

Code Screen Shot :

Output :

Add a comment
Know the answer?
Add Answer to:
Write a program that calculates Fibonacci numbers, as defined in section 2.4, definition 5. Demonstrate your...
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
  • (Demonstrate the Box class from above in a program), (Extra 5 Credits ). Re-use your code...

    (Demonstrate the Box class from above in a program), (Extra 5 Credits ). Re-use your code from the previous question, add the following functions. Each function worth 1 point. You dont have to implement in order. 1) Overloaded cout’s << that displays attributes of a box. Also overload cin’s >> operator to work with this class for constructing a Box instance using values supplied as console inputs. 2) Overloaded == operator as a member function that returns true if two...

  • 3. You should test your program on other test cases (tdhat you make up) as well....

    3. You should test your program on other test cases (tdhat you make up) as well. Making up good test cases is a valuable programming skill, and is part of ensuring your code solution is correct. Problem A: Number game (20 points) Write a C++ program that will play the following game. Ask the user how many "rounds" you want to play and start at 10 points. Every turn you can add either 1 point (by choosing "a or 2...

  • (10 marks) Question 1 Class Definitions la) (5 marks) Write information on Java class called IdentityCard...

    (10 marks) Question 1 Class Definitions la) (5 marks) Write information on Java class called IdentityCard to represent the the identity card of a member of an organisation. For example a UWA student card. Include brief comments in your class necessary, but full Javadoc is not required. State any a. definition as assumptions you make. The class should have: four fields that capture the person's name, identity number, photo, and whether the person is a current member of the organisation;...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • Below are a list of sequences of numbers. Your job is to program each sequence with...

    Below are a list of sequences of numbers. Your job is to program each sequence with any loop of your preference (while, for, do/while). I want the code to output the sequence provided and the next number in the sequence (you can output more but there is 1 sequence that may only have 1 number after). Each sequence should be in the same main in one .cpp file. . Please order and notate each sequence in your output –. The...

  • Part B (BI). Implement a Red-Black tree with only operation Insert(). Your program should read from...

    Part B (BI). Implement a Red-Black tree with only operation Insert(). Your program should read from a file that contain positive integers and should insert those numbers into the RB tree in that order. Note that the input file will only contain distinct integers. Print your tree by level using positive values for Black color and negative values for Red color Do not print out null nodes. Format for a node: <Node_value>, <Parent_value>). For example, the following tree is represented...

  • Instructions: For this assignment, you will write the first part of a program that allows a...

    Instructions: For this assignment, you will write the first part of a program that allows a customer to plan for retirement. Note: This program has no user input Write a "pure" Python function named 'calc_final_balance' that calculates the final balance in a retirement account after annual savings accrue for and earn interest for a number of years. This is a simulation problem similar to the Credit Card sample program, except it is to be written as a function definition (which...

  • CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50...

    CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50 Points) Please do the following exercises: Pastoral College is a small college in the Midwest. Design the pseudo-code for a program that accepts a student name, major field of study, and grade point average. Display a student’s data with the message “Dean’s list” if the student’s grade point average is above 3.5, “Academic probation” if the grade point average is below 2.0, and no...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • Prelab Exercises Your task is to write a Java program that will print out the following...

    Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...

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