|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
void main()
{
double x, a, b, i;
printf("please input a number: ");
scanf("%lf",&x);
if(x > 4)
{
i = 1.0;
b = 2.0;
}
else if(x>1 && x<4)
{
i = 0.1;
b = 1.0;
}
else if(x>0 && x<1)
{
i = 0.1;
b = 0.0;
}
else if(x == 4)
{
b = 2;
}
else if(x == 1)
{
b = 1;
}
else if(x == 0)
{
b = 0;
}
else
{
printf("a wrong number.\n");
}
while(1)
{
a = b * b;
if(a == x)
{
break;
}
else if(a > x)
{
b = b - i;
i = i / 10;
b = b + i;
}
else
{
b = b + i;
}
if(i <=0.000001)
{
break;
}
}
printf("%lf\n",b);
}
|
|