循环-10. 求序列前N项和*
/*
* 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 ;
}

不完美...
题目链接:
http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-10
,
,
,
循环-10. 求序列前N项和*的更多相关文章
- 循环-10. 求序列前N项和(15)
#include<iostream>#include<iomanip>using namespace std;int main(){ double i,n,t,a,b; ...
- 循环-21. 求交错序列前N项和
/* * Main.c * C21-循环-21. 求交错序列前N项和 * Created on: 2014年8月18日 * Author: Boomkeeper ***********测试通过**** ...
- 05-0. 求序列前N项和(15)
本题要求编写程序,计算序列 2/1+3/2+5/3+8/5+... 的前N项之和.注意该序列从第2项起,每一项的分子是前一项分子与分母的和,分母是前一项的分子. 输入格式: 输入在一行中给出一个正整数 ...
- 10. 求N分之一序列前N项和
求N分之一序列前N项和 #include <stdio.h> int main() { int i, n; double item, sum; while (scanf("%d& ...
- 39. 求分数序列前N项和
求分数序列前N项和 #include <stdio.h> int main() { int i, n; double numerator, denominator, item, sum, ...
- 20. 求阶乘序列前N项和
求阶乘序列前N项和 #include <stdio.h> double fact(int n); int main() { int i, n; double item, sum; whil ...
- 19. 求平方根序列前N项和
求平方根序列前N项和 #include <stdio.h> #include <math.h> int main() { int i, n; double item, sum; ...
- 11. 求奇数分之一序列前N项和
求奇数分之一序列前N项和 #include <stdio.h> int main() { int denominator, i, n; double item, sum; while (s ...
- 练习2-14 求奇数分之一序列前N项和 (15 分)
练习2-14 求奇数分之一序列前N项和 (15 分) 本题要求编写程序,计算序列 1 + 1/3 + 1/5 + ... 的前N项之和. 输入格式: 输入在一行中给出一个正整数N. 输出格式: 在一行 ...
随机推荐
- EF 拉姆达 动态拼接查询语句
EF 动态拼接查询语句 using System; using System.Collections.Generic; using System.IO; using System.Linq; usin ...
- NASM mode for Emacs
NASM mode for Emacs Quick post for those Emacs users out there. The common assembler used on GNU ...
- Java iText5.5.1 绘制PDF表格
iText下载链接:http://sourceforge.net/projects/itext/files/ 会有两个文件夹:extrajars中的extrajars-2.3.jar文件用于解决中文不 ...
- javascript 之 location.href、跨窗口调用函数
location.href这个东西常常用于跳转,location既是window对象的属性,又是document对象的属性. JavaScript hash 属性 -- 返回URL中#符号后面的内容 ...
- python hook监听事件
python hook监听事件 作者:vpoet mail:vpoet_sir@163.com # -*- coding: utf-8 -*- # # by oldj http://oldj.net/ ...
- A canvas fillText and strokeText example
A canvas fillText and strokeText example A canvas fillText and strokeText example
- OGG常见问题处理
1403: ORA-01403: No data found 在运行PL/SQL块.存储过程.函数.触发器等,假设须要进行操作的记录没有查询到.则会返回1403的错误 Goldengate中的1403 ...
- 检查ORACLE的警告文件的脚本
检查两天内的须要重视的信息: vi alter_error.sh echo "Check Alter Error:" cat $TRACE/alert_$ORACLE_SID. ...
- Linux FTP安装与简单配置
1.检測是否原有启动 ps -ef|grep vsftpd 2.检測是否有安装包 rpm -qa|grep vsftpd 3.假设有输出.查看状态并启动 service vsftp status - ...
- MFC多线程内存泄漏问题&解决方法
在用visual studio进行界面编程时(如MFC),前台UI我们能够通过MFC的消息循环机制实现.而对于后台的数据处理.我们可能会用到多线程来处理. 那么对于大多数人(尤其是我这样的菜鸟),一个 ...