C语言求一个数的平方根

include<stdio.h>

#include<math.h>

void main()

{

float a,x1=1,x2,t=0;                   (赋值)

printf("请输入一个数:\n");

scanf("%f",&a);

 x2=(1/(2.0))*(x1+a/x1);

    while(fabs(x2-t)>0.00001)            (精确度)

{  

  x2=(1/(2.0))*(x1+a/x1);

  t=x1;                           (相互记录值)

  x1=x2;

}

printf("%.2f的平方根为:%.5f\n",a,x2);

}

posted @ 2013-12-12 19:09  Latent_Truth  阅读(5370)  评论(0编辑  收藏  举报