我在C#中有一个小方法,目的是解决这个[[基本方程:
我是手动给
n和x值
我们将假定X
的值为3,而n的值为1。如果我评估方程式,则会得到以下结果:我的问题是输出为0,我也尝试解析结果
,但仍为0。实际结果是0.88888888
,但是在程序输出中我刚得到了0。这是我的代码:using System;
namespace Polinomio
{
class Program
{
static void Main(string[] args)
{
int x = 3;
int n = 1;
double result = 0;
for (int i = 0; i <= n; i++) {
result += (double)(Math.Pow((x - 1) / 3, Math.Pow(2, i))) / Math.Pow(2, i);
}
Console.WriteLine(result);
}
}
}
我不知道我做错了什么或我想念什么,我将提供任何帮助。
double x = 3;
int n = 1;
这将解决问题。