Precision of Square Root

Why my precision is not going over 5 digits?
#include
using namespace std;

int main()
{
int N,P,ct;
double i=1,ans;
cin>>N>>P;

ans=0;
for(ct=0;ct<=P;ct++)
{
while(ans*ans<=N)
{
ans=ans+i;

}
ans=ans-i;
i=i/10;
}

cout<<ans;
return 0;

}

Header is not visible properly. I typed it though.

@rishabhindora please describe the problem statement, right now it is not visible to be due to some technical glitch

So according to your code, you are trying to find the square root of number n with precision P.
Okay so here the problem is whenever our variable is going above the precision of 5, sometimes here it has been rounded off while priniting by the printing functions like printf and cout.
so before printing you can set the precision by the function.

> cout.precision(P);
> cout<<ans;

it is also suggestion to print the precision atlease 1 or 2 more than the required as still there are chances of roundoff.

I hope you find something useful.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.