Reference no: EM13159209
First, put both functions into a single file, and comment out the print statements in both functions. If you don't comment them out, you will get lots of output that you do not want.
Then, after the functions, read in the initial number for generating the sequences. Here, check that it is a positive integer. If it is not, give an error message and exit the program. (See below.)
Use the time.clock() function to time each function. To get a good value, call each function 10,000 times, noting the time before the calls and the time after the calls. Then divide the time by 10,000 to get the average time per call to the function. Print the average time the iterative function takes, the average time the recursive function takes, andwhich is faster and by how much (see below).
Input. Your program asks the user for a number, reads it in and checks that it is a positive integer, exiting with an error message if not.
Here is what a correct input should look like (the red text is what you type):
Compute the Collatz sequence for this number: 27
If the input is invalid:
Compute the Collatz sequence for this number: hello
Need a non-negative integer
and then the program exits.
Output. The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.
Your output for the input 27 should look exactly like this:
Average iterative Collatz time: 2.29415e-05 seconds
Average recursive Collatz time: 3.31636e-05 seconds
Iterative version is faster by 1.02221e-05 seconds
except that your times, which is faster, and the difference, may vary.
When printing the times, and the difference of the times, use the %g format (not the %e or %f formats). When printing which is faster, say "Iterative version is faster by ...", "Recursive version is faster by ...", or "Recursive and iterative versions are equally fast".
Allows the user to enter the coefficients for a system
: Create a graphical (not text-based) Visual C++ program that allows the user to enter the coefficients for a system of four equations with four unknowns. Include a button that when clicked, will solve the system of equations and display the results in..
|
Write a xml schema for the validation of the document notes.
: write a XML schema for the validation of the document notes.xml. Write the schema according to the following three approaches;1.- Based on the document structure2.- Structured (bottom-up design)3.- Type-based (top-down design)
|
Program to compute the total volume
: Write a program to compute the total volume for a number of cylinders. A cylinder may have different values for height and radius.
|
Create a calculator function
: This is the code for my trip planner,you need to figure out how to create a calculator function to enable users to calculate their own costs if they choose
|
The initial number for generating the sequences
: Then, after the functions, read in the initial number for generating the sequences. Here, check that it is a positive integer. If it is not, give an error message and exit the program.
|
Write an array where the user can input 7 temperatures
: Write an array where the user can input 7 temperatures; include a 'for' loop. Make sure the temperatures are larger than -100 and smaller than or equal to 120, if not, make sure the user enters a valid number. Make sure the temperature is between the..
|
We are interrupted or disintegrated
: Research is compelling that it takes us approximately 4 to minutes return to our work with the same level of through processes whenever we are interrupted or disintegrated. Is it possible to information is fairly constant?
|
Explain why you classify them as nonvalue-added activities
: List the activities in the doctor's office that are candidates for nonvalue-added activities. Explain why you classify them as nonvalue-added activities.
|
Find the corresponding minimum cost function
: Does this production function display increasing, constant or decreasing returns to scale and find the corresponding minimum cost function assuming that w 1 and w 2 are given.
|