c语言编程求数列的1/1-1/3+1/5-1/7+1/9……前20项的累计和?
得到的答案是1.00,错的。但是,错在哪了?求助#include<stdio.h>intmain(){intnum=1,sign=1,term=1;doublesum=1...
得到的答案是1.00,错的。但是,错在哪了?求助
#include<stdio.h>
int main()
{
int num = 1, sign = 1, term = 1;
double sum = 1.00;
while (num <= 20)
{
sign = -sign;
term = term + 2;
sum = sum + (sign / term);
num++;
}
printf("前20项和=%0.2f", sum);
} 展开
#include<stdio.h>
int main()
{
int num = 1, sign = 1, term = 1;
double sum = 1.00;
while (num <= 20)
{
sign = -sign;
term = term + 2;
sum = sum + (sign / term);
num++;
}
printf("前20项和=%0.2f", sum);
} 展开
展开全部
#include <stdio.h>
int main()
{
int num = 1, sign = 1, term = 1;
double sum = 1.00;
while (num <= 20)
{
sign = -sign;
term = term + 2;
sum = sum + ( (double) sign / term);
num++;
}
printf("前20项和=%0.2f", sum);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询