Pages

Thursday, July 11, 2013

Recursive Square root function in C++

/*
QUESTION:
Write Recursive square root function


CODE:
*/

#include<iostream.h>   
double sqrt( int n,int rep=0)
static double x=1;
if(n<=rep)

 return 0;
else
x=0.5*(x+n/x);
 sqrt(n,++rep);
return x;
 }  
int main()
{
int a;
cout<<"enter the a"<<endl;
cin>>a;
cout<<sqrt(a)<<endl;
}
 

No comments:

Post a Comment