1131 -- 数列求和
来源:互联网 发布:查找重复删除知乎 编辑:程序博客网 时间:2024/06/08 07:52
数列求和
Time Limit:2000MS Memory Limit:65536K
Total Submit:294 Accepted:154
Description
有一个分数序列:2/1,3/2,5/3,8/5,13/8 。。。。
输入一数,求出这个数列前n项之和(n<20)。
Input
输入为一个整数,表示要求的前几项数列
Output
以浮点数输出前n项的和
Sample Input
样例输入:2
Sample Output
样例输出:3.500
Source
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AK1131 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int a = 2, b = 1; double sum = 0; for (int i = 0; i < n; i++) { sum += a * 1.0 / b; int c = a; a = a + b; b = c; } Console.WriteLine(sum.ToString("0.000")); //Console.ReadLine(); } } }
0 0
- 1131 -- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 数列求和
- 求和数列
- xml之SAX解析
- x64 release模式下mysql编译连接错误解决办法
- java httpclient basic授权
- Hadoop第4周练习—HDFS读写文件操作
- 删除字符串中的空格字符
- 1131 -- 数列求和
- C++动态数组使用方法
- apache cgi机制核心实现代码
- 遵从CLS
- 26. 面向对象程序设计
- An Efficient Resource Allocation Scheme for Cross- Cloud Federation
- 1132 -- 三角形面积
- memcpy, strcpy, strlen, strcmp, itoa, atoi 的函数实现
- CheckBox选择框和文字设置间距