View Code of Problem 74

#include<stdio.h>
#include<math.h>
int main()
{
	int x;
	double x1,x2;
	scanf("%d",&x);
	x1=(double)x;
	x2=1.0/2*(x1+(double)x/x1);
	while(fabs(x2-x1)>=0.00001)
	{
		x1=x2;
		x2=1.0/2*(x1+(double)x/x1);
	}
	printf("%.3lf",x2);
	
	
	return 0; 
}

Double click to view unformatted code.


Back to problem 74