View Code of Problem 74

#include<cstdio>
#include<cmath>
int main(){
	int a;
	double x1,x2;
	scanf("%d",&a);
	x1=double (a)/2;
	x2=(x1+a/x1)/2;
	while(fabs(x2-x1)>=1.0e-5){
		x1=x2;
		x2=(x1+a/x1)/2;
	}
	printf("%.3lf",x2);
	return 0;
}

Double click to view unformatted code.


Back to problem 74