博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电oj-2011 多项式求和 C++
阅读量:4033 次
发布时间:2019-05-24

本文共 514 字,大约阅读时间需要 1 分钟。

Problem Description

多项式的描述如下:
1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + …
现在请你求出该多项式的前n项的和。

Input

输入数据由2行组成,首先是一个正整数m(m<100),表示测试实例的个数,第二行包含m个正整数,对于每一个整数(不妨设为n,n<1000),求该多项式的前n项的和。

Output

对于每个测试实例n,要求输出多项式前n项的和。每个测试实例的输出占一行,结果保留2位小数。

Sample Input

2
1 2

Sample Output

1.00
0.50

代码

#include
#include
using namespace std;int main(){ int m; int n;//临时存放测试的数 double sum; int a[101]; //存放m个测试数据 while(cin>>m){ for(int i=0;i
>n; a[i]=n; } for(int i=0;i

转载地址:http://vafdi.baihongyu.com/

你可能感兴趣的文章
【剑指offer】面试题28的习题:正方体,八皇后
查看>>
【剑指offer】面试题42:单词翻转顺序&左右旋转字符串
查看>>
【剑指offer】面试题43:n个骰子的点数
查看>>
堆排序及其相关操作
查看>>
【剑指offer】 堆排序查找最小的K个数
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Word Break(python)
查看>>
【剑指offer】面试题26:复杂链表的复制
查看>>
【leetcode】Candy(python)
查看>>
【leetcode】Clone Graph(python)
查看>>
【leetcode】Sum Root to leaf Numbers
查看>>
【leetcode】Pascal's Triangle II (python)
查看>>
windows下 pip安装
查看>>
线程和进程
查看>>
UNIX 学习笔记-文件I/O(open)
查看>>
UNIX学习笔记-文件I/O--(creat,close)
查看>>