Solution: Newton's Method

Solution: Newton's Method

C
#include <stdio.h>
int main(void)
{
double num = 612;
double x1 = 10;
double xi;
int i;
for (i = 1; i <= 5; i++) {
// No need to continue if the exact solution has been found
if (x1 * x1 - num == 0) {
break;
}
// Find a better approximation
xi = x1 - ( ((x1 * x1) - num) / (2 * x1) );
printf("x%d = %.12f, x%d = %.12f\n", i, x1, i + 1, xi);
x1 = xi; // x1 is now the new approximation.
}
return 0;
}