循环-10. 求序列前N项和*

时间:2024-01-07 21:21:08
 /*
* Main.c
* C10-循环-10. 求序列前N项和
* Created on: 2014年7月30日
* Author: Boomkeeper
*******部分通过*******
*/ #include <stdio.h> int main(void) { double sum = 0.0; //记录前N项和
int numerator = ,denominator = ; //分子分母
int N; //题目中的N
int i;//循环使用
int tem = ; scanf("%d", &N); if (N == )
printf("%.2f\n", (double) numerator / denominator);
else {
sum = (double) numerator / denominator;
for (i = N; i > ; i--) {
tem = denominator;
denominator = numerator;
numerator = numerator + tem;
sum += (double) numerator / denominator;
}
printf("%.2f\n", sum);
} return ;
}

循环-10. 求序列前N项和*

不完美...

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-10