This is an example of finding square roots. I have to maintain this procedure to find the square root of any given number.
I have got a problem that, I have to find the square root of any given number without using the sqrt()
function in C. And I have to follow this procedure that I have showed in this image. I have solved one. Here's my code:
int main(){
double i,j,n;
printf("Enter a number\n");
scanf("%lf",&n);
j=n;
for(i=1;i<=n*2;i++)
{
j=(j+(n/j))/2;
}
printf("\nresult is %.4lf",j );
return 0;
}
Is this code maintaining the procedure that is given in the image? If it is not, please how I should solve it? I am a beginner. If there's anything wrong, please tell me.