编写程序求:s=1-1/3+1/5-1/7+1/9-…1/99的值
1个回答
展开全部
#include<stdio.h>
#include<math.h>
int main()
{
double sum = 0;
double tmp = 0;
unsigned int num = 0;
int count = 1;
int flag = 0;
scanf("%d",&num);
while(num >= count)
{
tmp = pow(-1.0,flag);
sum = sum + 1.0/(tmp*count);
count = count + 2;
flag = flag + 1;
}
printf("sum = %f",sum);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询