http://www.dreamincode.net/code/snippet244.htm
[cpp]
/* Code written by Sanchit Karve
A.K.A born2c0de
Contact Me at born2c0de AT hotmail.com
20 August, 2005
*/
#include
#include
using namespace std;
float sqroot(float m)
{
float i=0;
float x1,x2;
while( (i*i) <= m )
i+=0.1;
x1=i;
for(int j=0;j<10;j++)
{
x2=m;
x2/=x1;
x2+=x1;
x2/=2;
x1=x2;
}
return x2;
}
int main()
{
cout << "Enter a Number:";
int no;
cin >> no;
cout << "Square Root using sqroot()= " << sqroot(no) <
return 0;
}
[/cpp]
No comments:
Post a Comment