I have an array of the first 50 Fibonacci numbers in the picture.
Your
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
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- You need to allocate an area in memory for storing an array of 30 bytes. The first byte will have the value 0 stored in it, the second ,1, the third ,2, etc. This memory area will start at location .00100e. Show what this area of memory looks like.arrow_forwardYou have FOUR people selling 5 different kinds of flowers, so instead of a 4 by 4 array you had in the video (4 rows and 4 columns) you now have a 4 by 5 array (4 rows and 5 columns ) You may either use the names I had in the video or choose your own. Instead of Brownies, you have flowers - petunia, pansy, rose, violet, and carnation. Use a random number generator to generate the numbers of flowers sold, print out all the data as I did in the video. The output should look like this: (numbers will vary because they are randomly generated) petunia pansy rose violet carnationFrankie 5 3 11 3 16 Janet 0 11 11 20 6 Sam 14 16 17 15 1 Abbie 8 20 0 6 8 Frankie sold 38 flowersJanet sold 48 flowersSam sold 63 flowersAbbie sold 42 flowers Total number of petunias sold: 27Total number of pansies…arrow_forwardYou are give an array which contains the following integers : 9, 10, 12, 15, 7, 2, 1, 16, 18, 5, 6. Write a java program that will give you the product of this arrayarrow_forward
- Write a program where the user enters 10 floating point numbers into an array and it shows the numbers that are greater than the average. Input = 7.5 3.0 4.9 2.8 8.4 6.6 2.4 6.1 3.7 1.5 Output = 7.5 4.9 8.4 6.6 6.1 Input = 2.3 11.76 10.32 12.4 5.91 5.68 9.3 4.6 13.47 10.1 Output = 11.7 10.3 12.4 9.3 13.4 10.1 Requested files main.c 1 Binclude 2 3- int main(O 4 // Write your code here.. return(0);arrow_forwardThe Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, ... where each number (after the first two values) is the sum of the previous two numbers. Write a program that declares an integer array called fib_numbers with a length of 25 elements. The program then fills the array with the first 25 Fibonacci numbers using a loop. The program then prints the values to the screen using a separate loop.arrow_forwardUse an array. The program should read 25 integers from a user. Each value should be between 5- 100 (5<-value<-100). As the user inputs values store all the values which are not a duplicate. Print all the array values at the end. Use the smallest possible array.arrow_forward
- Program: Using a multidimensional array, create a triangular-shaped array. You will ask the user how many lines they want to see and then create the array, fill it, and then print it. You will fill the array with one 1 in the first row, two 2’s in the second row, etc. This should work for any integer that the user enters. (Just because I am starting on 1 does not mean row 0 was skipped.) You must: use a loop to create the array shape. You must: use nested for loops to fill the array and to print the values back to the screen. Your program should print as shown below. Example Output: How many lines would you like in your triangle? >>>9 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 If your code looks like the code below, it is not what I’m asking for. The code below is making a square multidimensional array, not a triangular one. The code below is just leaving certain spots empty so that it looks like a triangle. I will ask you…arrow_forwardDesign a program that asks the user to enter a store’s sales for each day of a 7 day week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week, the average sales per day, and also display the list of values. This is for java.arrow_forwarduse the array built to shuffle and deal two poker hands. Change the corresponding values for all Jacks through Aces to 11, 12, 13, 14 respectively. Shuffle the deck, then deal two hands. Comment your code and submit the Python code. i wrote a code for it but its not displaying properly, can someone tell me why? (black and white is the array given/ the picture of the python app is what i wrote) its only displaying the array given and not the bottom code i put, why?arrow_forward
- Draw an array that shows why 20∙19=20∙20−20∙1. Also, use this equation to help you calculate 20∙19 mentally.arrow_forwardThe Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly The sum of each row, each column and each diagonal all add up to the same number. This is shown below: Write a program that simulates a magic square using 3 one dimensional parallel arrays of integer type. Do not use two-dimensional array. Each one the arrays corresponds to a row of the magic square. The program asks the user to enter the values of the magic square row by row and informs the user if the grid is a magic square or not. Processing Requirements - c++ Use the following template to start your project: #include<iostream> using namespace std; // Global constants const int ROWS = 3; // The number of rows in the array const int COLS = 3; // The number of columns in the array const int MIN = 1; // The value of the smallest number const int MAX = 9; // The value of the largest number //…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education