im tryin to compare the time it takes to calculate squareroot by the stdlib function and recursive function. everythin's workin good except the TIME thing. its givein me the same time. wat is wrong??? plz help me find it.. thank you guys!
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
double sqroot(double,double,double);
void main()
{
int j,k,dif; double x,y,z; double a,b;
z=0.01; y=2;
cout<<"Enter the number you want to find the squareroot of : ";
cin>>x;
a=sqrt(x);
j=time(0);
b=sqroot(x,y,z);
k=time(0);
dif=k-j;
cout<<"By using the cstdlib the ans is :"<<a<<endl;
cout<<"The time it took to calculate: "<<j<<endl;
cout<<"By using the recursive function the ans is :"<<b<<endl;
cout<<"The time it took to calculate: "<<k<<endl;
}
double sqroot(double num, double ans, double tol)
{
if (fabs((ans*ans)-num)<=tol)
return ans;
else
return sqroot(num,((ans*ans)+num)/(2*ans),tol);
}