1040: 数列求和1
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 11517 Solved: 8349
Submit Status Web Board
Description
输入一个整数n,输出数列1+1/3+1/5+……前n项的和。
Input
输入只有一个正整数n。
Output
结果保留2为小数,单独占一行
Sample Input
3
Sample Output
1.53
HINT
Source
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,i;
double s=0.0;
scanf("%d",&n);
i=1;
while(n--)
{
s += 1.0/i;
i += 2;
}
printf("%.2f\n",s);
return 0;
}