The Fibonacci sequence occurs frequently in nature as the growth rate for certain idealized animal populations. The sequence begins with 0 and 1, and each successive Fibonacci number is the sum of the two previous Fibonacci numbers. Hence, the first ten Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The third number in the series is 0 + 1, which is 1; the fourth number is 1 + 1, which is 2; the fifth number is 1 + 2, which is 3; and so on.
Besides describing population growth, the sequence can be used to define the form of a spiral. In addition, the ratios of successive Fibonacci numbers in the sequence approach a constant, approximately 1.618, called the “golden mean”. Humans find this ratio so aesthetically pleasing that it is often used to select the length and width rations of rooms and postcards.
Use a recursive formula to define a static method to compute the nth Fibonacci number, given n as an argument. Your method should not use a loop to compute all the Fibonacci numbers up to the desired one, but should be a simple recursive method. Place this static recursive method in a
Fibonacci #1 = 0
Fibonacci #2 = 1
Fibonacci #3 = 1; 1/1 = 1
Fibonacci #4 = 2; 2/1 = 2
Fibonacci #5 = 3; 3/2 = 1.5
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Concepts of Programming Languages (11th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Software Engineering (10th Edition)
C How to Program (8th Edition)
Problem Solving with C++ (10th Edition)
Concepts Of Programming Languages
- In number theory, a happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit. For instance, 13 is a happy number because 1² +3² = 10 and 1² + 0² = 1. On the other hand, 4 is not a happy number because the sequence starting with 4² 16 and 126² = 37 and eventually reaches to 4 that is the number that started the sequence, and so the process continues in an infinite cycle without ever reaching 1. Write, Compile and Execute a Java method that computes whether a given number is happy or sad.arrow_forwardQ3: Interplanetary Spaceflight Milan Tusk is the richest person in the universe. After devoting decades of his life to further our space exploration technologies, he’s finally ready to retire. Being a space enthusiast, the first thing he wants to do is visit n planets p1, p2, …, pn, in this order. He’s currently on planet p0. Milan knows that the distance between planets pi and pi + 1 (for 0 ≤ i < n) is d[i]light years. His spaceship uses 1 tonne of fossil fuels per light year. He starts with a full tank and can fill up his tank at any of the n planets (but he must not run out in between two planets). There’s a huge cost to set up the spaceship for refuelling. Due to financial constraints (he’s not THAT rich), he can fill up his tank at most ktimes. In order to save money and make his spaceship lighter, Milan is looking for the smallest possible fuel tank that enables him to complete his space travel and reach planet pn. What is the smallest tank capacity that enables him to do so?…arrow_forwardThe nth Fibonacci number F, is defined as follows: Fo = 1, F1 = 1, and F = Fn-1 + Fn-2 for n> 1 In other words, each number is the sum of the two previous numbers in the sequence. Thus, the first several Fibonacci numbers are 1, 1, 2, 3, 5, and 8. Interestingly, certain population growth rates are characterized by the Fibonacci numbers. If a population has no deaths, then the series gives the size of the population after each time period. Assume that a population of green crud grows at a rate described by the Fibonacci numbers and has a time period of 5 days. Hence, if a green crud population starts out as 10 pounds of crud, then after 5 days, there is still 10 pounds of crud; in 10 days, there is 20 pounds of crud; in 15 days, 30 pounds of crud; in 20 days, 50 pounds of crud, and so on. Write a program that takes both the initial size of a green crud population (in pounds) and some number of days as input from the keyboard, and computes from that information the size of the population…arrow_forward
- The greatest common divisor of two positive integers, A and B, is the largest number that can be evenly divided into both of them. Euclid's algorithm can be used to find the greatest common divisor (GCD) of two positive integers. You can use this algorithm in the following manner: 1. Compute the remainder of dividing the larger number by the smaller number. 2. Replace the larger number with the smaller number and the smaller number with the remainder. 3. Repeat this process until the smaller number is zero. The larger number at this point is the GCD of A and B. Write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. An example of the program input and output is shown below: Enter the smaller number: 5 Enter the larger number: 15 The greatest common divisor is 5arrow_forwardA year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: The year must be divisible by 4 If the year is a century year (1700, 1800, etc.), the year must be evenly divisible by 400 Some example leap years are 1600, 1712, and 2016. Write a program that takes in a year and determines whether that year is a leap year. Ex: If the input is 1712, the output is: 1712 is a leap year. Ex: If the input is 1913, the output is: 1913 is not a leap year. 1 2 3 4 5 6 7 8 9 10 11 Put("{} is a leap year.".format(i_year)) print("{} is not a leap year.".format(i_year)) inputYear = Get next input What would be the code?arrow_forward1.In an ancient land, the beautiful princess Eve had many suitors. She decided on the following procedure to determine which suitor she would marry. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the secondnumber 2, and so on up to the last suitor, number n. Starting at the first suitor she would then count three suitors down the line (because of the three letters in her name) and the third suitor would be eliminated from winning her hand and removed from the line. Eve would then continue, counting three more suitors, and eliminating every third suitor. When she reached the end of the line she would continue counting from the beginning. For example, if there were 6 suitors then the elimination process would proceed as follows:123456 initial list of suitors, start counting from 112456 suitor 3 eliminated, continue counting from 41245 suitor 6 eliminated, continue counting from 1125 suitor 4 eliminated, continue…arrow_forward
- Little Frank loves mathematics. Every day, he solves some mathematical problems to improve his skill. A few days ago, he found a popular problem about turtles. The problem is as follows. Little Frank is given R rectangles, numbered 1 through R. The width and height of the i-th rectangle are Ni and M¡ unit respectively. There is a turtle located on the top-left corner of each rectangle. For each rectangle, count the number of ways the turtle can reach the bottom-right corner, if each turtle can only move right or down 1 unit at any time. The turtle is not allowed to move outside the rectangle, but, of course, the turtle can move on the boundary of the rectangle. In less than one second, this problem was solved for all rectangles. He felt that the problem was too easy. This morning, Little Frank wanted more challenges. Thus, for each rectangle į, he cut and removed a rectangle of A¡ x Bị unit from the top-right corner. See the following figure for detail. Bị Mi He could not solve this…arrow_forwardA geometric sequence is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non - zero number called the common ratio. For example, the sequences 2, 6, 18, . ... 3, 15, 75 , …. are a geometric sequences with common ratios 3 and 5 respectively. A geometric sequence is generally characterized by three numbers, the first term ‘ a’, the common ratio ‘ r’ and the number of terms ‘ n’. A geometric series is the sum of numbers in a geometric sequence. 2+ 6+ 18 and 3+ 15+ 75 are examples of geometric series with three terms each. The nth term of a geometric series with initial value ‘ a’ and common ratio ‘ r’ is given by: ?? = ???−1. While the sum of a geometric series is given by: ?(1-??−1) / 1-??−1 Create a class Geometric Series to model a Geometric series. Using friend function, overload the ‘~’ operator to find the nth term of the series. Likewise, overload the ‘!’ operator (using a friend function)…arrow_forwardSummary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (In other words, equal amounts of red, green, blue yield gray). Given values for red, green, and blue, remove the gray part. Ex: If the input is: 130 50 130 the output is: 80 0 80 Find the smallest value, and then subtract it from all three values, thus removing the gray. Note: This page converts rgb values into colors. 461710.3116374.qx3zqy7 LAB ACTIVITY 1 111 4.10.1: LAB: Remove gray from RGB Type your code here. 111 main.py 0/10 Load default template...arrow_forward
- Tiling: The precondition to the problem is that you are given threeintegers n, i, j, where i and j are in the range 1 to 2n. You have a 2n by 2n squareboard of squares. You have a sufficient number of tiles each with the shape . Your goalis to place nonoverlapping tiles on the board to cover each of the 2n × 2n tiles except forthe single square at location i, j. Give a recursive algorithm for this problem in whichyou place one tile yourself and then have four friends help you. What is your base case?arrow_forwardA perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. Equivalently, a perfect number is a number that is half the sum of all of its positive divisors. The first perfect number is 6, because 1, 2 and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: (1 + 2 + 3 + 6) / 2 = 6.Write a program to display the of sum all perfect numbers found in the first 1000 integers in javaarrow_forwardA perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. Equivalently, a perfect number is a number that is half the sum of all of its positive divisors. The first perfect number is 6, because 1, 2 and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: (1 + 2 + 3 + 6) / 2 = 6. Write a program to display the of sum all perfect numbers found in the first 1000 integers.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr