发布网友 发布时间:2024-10-24 13:29
共1个回答
热心网友 时间:2024-11-01 17:22
double x, delta, result;
x = 2d; // x初始值设为2,因为2^2 < 10
delta = 0.1d; //x的增量
x += delta;
result = Math.Pow(x, x); //结果
while (Math.Abs(result - 10) > 0.000001) //误差控制在0.000001
{
if (result > 10)
{
x -= delta;
delta /= 10;
x += delta;
result = Math.Pow(x, x);
continue;
}
x += delta;
result = Math.Pow(x, x);
}