Approximating the square root using an iterative method I wrote this code, based on the Newton-Raphson method, to find the square root of a number. I'm wondering how I can optimise this code, as I am out of ideas.

#include &lt;stdio.h&gt;

int main(void)
{
     float n, x, i;

     printf("Enter the number you wish to find the square root of.\n");
     printf("\n");
     scanf("%f", &amp;n);

     x = n/2;

     for (i = 0; i &lt; 100; i++)
         x = x - (((x*x) - n)/(2*x));

     printf("The square root of %.0f is %.4f.\n", n, x);

     return 0;

}
Do not rely on a fixed number of iterations. Stop when reaching a desired discrepancy (e.g. fabs(x*x - n) &lt; epsilon)
I do not see any reason for not simplifying the calculations into x = (x + n/x)/2.0.
Assure that the input is positive.