So i was watching the lecture on how to find square root of a number, and i tried to write the code a little differently from what was taught in the video. Although the code seems to run fine, i think there is some error. Since i can’t locate it, i need help. I have written my code below.
#include
using namespace std;
int main()
{
int N;
float n = 0;
float x = 1.0;
float P;
cout<<"Enter the number whose square root is to be found: ";
cin>>N;
cout<<"Enter the precison P: “;
cin>>P;
for(; P<=x; x = x/10)
{
for(; n*n<=N; n = n + x)
{}
n = n - x;
}
cout<<n<<” is the approximate square root of "<<N;
return 0;
}