#include"stdio.h"#include"string.h"#include"conio.h"#include"windows.h"#include"math.h"double funa (int n);int main(){ double u; int y; printf("请输入分母的值:");scanf("%d",&y); u = funa ( y ); printf(" %f \n",u); return 0;}double funa (int n){ double add = 0; double t; int k; int s = 1; for ( k = 1;k <= n; k ++ ) { s = -s; t = s * 1.0/k; add = add + t; } return add;}
1 回答
已采纳
望远
TA贡献1017条经验 获得超1032个赞
s = -s; t = s * 1.0/k;
这两行代码应该换一下顺序,否则加的第一个数是-1
2.
printf(" %f \n",u);
double类型数据应该%lf格式输出
- 1 回答
- 0 关注
- 1357 浏览
添加回答
举报
0/150
提交
取消