View Code of Problem 74

#include <stdio.h>
#include <math.h>
int main()
{
	int i,X;
	scanf("%d", &X);
	float x[50];
	x[0] = X / 2.0;
	for (i = 1;; i++)
	{
		x[i] = 1 / 2.0 * (x[i - 1] + X/ x[i - 1]);
		if (fabs(x[i] - x[i - 1]) < 0.00001)
			break;
	}
	printf("%.3f\n", x[i]);
	return 0;
}

Double click to view unformatted code.


Back to problem 74