Input:

3

6

2

5

Output:

2

2

5

I know about finding the square root by hand procedure, but it's too hard for me to do it in a program. I used this code below but it's too slow and it't not for huge numbers.

#include <iostream> #include <math.h> 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)<<endl <<"Square Root using sqrt() = "<<sqrt(no); return 0; }

*mod edit: added code tags:

This post has been edited by **NickDMax**: 10 June 2009 - 06:56 PM