View Code of Problem 74

#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
	float x1,x2,a;
	scanf("%f",&a);
	x1=1.0;
	while(1)
	{
		x2=1.0/2*(x1+a/x1);   //循环求x2的值直到求到特定的参数 此处只有a是输入的变量;
		if(fabs(x1-x2)<0.00001)
		{
			printf("%0.3f",x2);
			break;
		}
		x1=x2;
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 74