Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

I have an array of the first 50 Fibonacci numbers in the picture.

Your program should ask the user for a number between 5 and 21.  Using that input as a location in the array, with that location and the next three locations (for example base, base+1, base+2 and base+3) you will multiply the outer values, base and base+3, (the first and last of the four). Do the same for the inner values (base+1 and base+2 multiplied) and then double that value.

 

These two values form the two sides of a right triangle.  Now find the hypotenuse.  Remember the Pythagorean theorem, which says a2 + b2 = c2.  Our two sides are a and b, so we square each of them (remember a * a = a2, so just multiply each value by itself) and add them together.  That gives you c2. Now all you need do is take the square root of that sum.

 

Given that the sqrt method normally returns a floating-point value (a double), we must force it to return a long integer for us in this case, so use the following line (with your own variable names of course) to get the square root.

 

long hypot =  (long)Math.sqrt((leg1*leg1) + (leg2*leg2));

 

Search your Fibonacci array for the hypotenuse value.  Your final output will be the value entered, the four Fibonacci numbers in the sequence starting at that location, the length of each leg, the length of the hypotenuse, and the index number (position) of the hypotenuse value in the Fibonacci array.  (And yes, the hypotenuse of the triangle will also be a Fibonacci number.)

 

Here is a sample output for a user entering the value 4: (Numbers greater than 21 will not be in your array.)

 

Enter a number between 5 and 21: 4  

5    8    13   21

leg 1 = 105, leg 2 = 208 and the hypotenuse = 233, which is Fibonacci position 12

 

long[] fib = new long[50];
int t1 = 0, t2 = 1;
System.out.print("First 50 terms: ");
%3D
for (long i = 1; i <= fib.length; ++i)
{
System.out.print(t1 + " ,");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
expand button
Transcribed Image Text:long[] fib = new long[50]; int t1 = 0, t2 = 1; System.out.print("First 50 terms: "); %3D for (long i = 1; i <= fib.length; ++i) { System.out.print(t1 + " ,"); int sum = t1 + t2; t1 = t2; t2 = sum; }
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education