Question
//Calculate the square root of a number using sqrt and pow #include #include #include using namespace std; int main () { time_t before; time_t after;
//Calculate the square root of a number using sqrt and pow
#include
#include
#include
using namespace std;
int main ()
{
time_t before;
time_t after;
double x;
double result;
int i;
/umber of times pow and sqrt will be called:
const int ITERATIONS = 1;
cout
cin >> x;
//your code goes here: record the time before using pow
before = _______________
for (i = 0; i
result = pow(x,0.5);
//your code goes here: record the time after using pow
after = _______________
cout
//complete the following lines so that
//the appropriate value is displayed
cout
cout
//your code goes here: record the time before using sqrt
before = _____________________
for (i = 0; i
result = sqrt(x);
//your code goes here: record the time after using sqrt
after = _______________
cout
//complete the following lines so that
//the appropriate value is displayed
cout
cout
return 0;
}
4a. Critical Thinking Exercise: In the previous exercise, it probably took your computer 0 seconds to use each of the functions for each of the input values. Both operations are so fast, that we cannot determine which one is faster. In order to do so, you will modify the sqrt2.cpp program so that each function is called a significant number of times for the same input value. To do this, change the value of ITERATIONS to 100000000. Save your program as sqrt3.cpp. Use the following space to write the line(s) you modified in your program. Compile, link, and execute the program. Fill the following table with the results from your program: Input Values (x) Time to calculate pow (x, 0.5), 100,000,000 times. Time to calculate sqrt(x), 100,000,000 times. HNT 13 121 1029 4b. Compare the results shown in the table above. Which function (pow or sqrt) is more efficient in calculating the square root of a number? 4a. Critical Thinking Exercise: In the previous exercise, it probably took your computer 0 seconds to use each of the functions for each of the input values. Both operations are so fast, that we cannot determine which one is faster. In order to do so, you will modify the sqrt2.cpp program so that each function is called a significant number of times for the same input value. To do this, change the value of ITERATIONS to 100000000. Save your program as sqrt3.cpp. Use the following space to write the line(s) you modified in your program. Compile, link, and execute the program. Fill the following table with the results from your program: Input Values (x) Time to calculate pow (x, 0.5), 100,000,000 times. Time to calculate sqrt(x), 100,000,000 times. HNT 13 121 1029 4b. Compare the results shown in the table above. Which function (pow or sqrt) is more efficient in calculating the square root of a numberStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started