循环-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. 输出格式: 在一行 ...
随机推荐
- syslinux 3.84 2009-12-18 ebios copyright (c) 1994-2009 H. Peter Anvin et al
使用USB方式安装win7+Ubuntu12.04双系统时出现"syslinux 3.84 2009-12-18 ebios copyright (c) 1994-2009 H. Peter ...
- servlet示例
当用户向客户端发送一个请求,如: [plain] view plaincopy http://localhost:8088/ServApp/myreq.cg?param1=param 当Soc ...
- NOI十连测 第四测 T1
思路:首先每个蚂蚁移速相同,而且碰到就转头,这其实等价于擦肩而过! 看到2n个数互不相同就觉得方便多了:枚举每个数字往左或者往右作为最慢,然后考虑其他蚂蚁有多少种走路方向. (1),走的距离大于m/2 ...
- LeetCode_Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- 在一个exe文件中查找指定内容,找到则返回起始位置, 否则返回0
//在一个exe文件中查找指定内容,找到则返回起始位置, 否则返回0//如果某字符串, 直接传入字符串进来//如果要查找16进制,则用如下格式传参进来: #$1A#$2A#$3A function F ...
- C# 客户端发送http请求代码 (c/s)
public class RestClient { private string BaseUri; public RestClient(string baseUri) { this.BaseUri = ...
- javascript之全局函数
一.eval() //执行一段字符串中的javascript代码. 语法:eval(code); //可以将javascript写在字符串里面执行. var str = "document. ...
- javascript之url转义escape()、encodeURI()和decodeURI()
我们可以知道:escape()除了 ASCII 字母.数字和特定的符号外,对传进来的字符串全部进行转义编码,因此如果想对URL编码,最好不要使用此方法.而encodeURI() 用于编码整个URI,因 ...
- C# ref_out_params方法的参数_4种类型的参数
之前学习C#没有做笔记的习惯,因此有些基础上的东西并没有很好地整理起来,虽然这些东西比较常用,因此也没什么影响,但总觉得不整理一下感觉老是有种陌生感.今天特别整理一下C#4种类型的参数. 一.按值传递 ...
- Unattended Setup Software Components (无人值守安装软件组件)
原文 http://social.technet.microsoft.com/Forums/windows/en-US/d4ad85b4-8342-4401-83ed-45cefa814ec5/una ...