Sqrt function errors incorporating
How would I incorporate the equation into my program? Basically adding a
new column of info when it compiles:
relative_error_per_cent = 100 *((my_sqrt_1(n) – sqrt(n)) / sqrt(n)
I know that it is suppose to go inside the for loop but what else is
missing? Im getting errors. Been trying at this for a while
#include <iostream>
#include <math.h>
using namespace std;
double my_sqrt_1(double n)
{
double x = 1;
for(int i = 1; i < 10; ++i)
x = (x+n/x)/2;
return x;
}
int main()
{
for(auto k : { -100,-10,-1,0,1,10,100})
{
double relative_error_per_cent = 100*((my_sqrt_1(n) – sqrt(n)) / sqrt(n))
double n=3.14159 * pow (10.0,k);
cout << n << sqrt(n) << my_sqrt_1(n) << relative_error_per_cent;
}
return 0;
}
No comments:
Post a Comment