编写一个程序,求S值(n由键盘输入):

(程序检验参考:x=6.66,n=8时,s=40.955;x=6.66,n=15时,s =-1.511)
2024-11-26 08:55:46
推荐回答(2个)
回答1:

int n = 8;
double s = 0;
for (int i = 1; i <= n; i++)
{
double x = 6.66;
int down = 1;
double up = x;
for (int j = i; j >= 2; j--)
{
up = up * x;
down = down * j;
}

if (i % 2 == 0)
{
s += up / down;
}
else
{
s -= up / down;
}
}

回答2:

请问:第五项是什么?