题解 | #牛牛学数列2#
牛牛学数列2
http://www.nowcoder.com/practice/fc72951f52984f3abd286d82eeffacba
因为输出的是小数,所以用浮点型,而且精度一定要高,不然过不去,直接double。
int main()
{
int n = 0;
double sum = 0;
scanf("%d",&n);
for(double i = 1;i<=n;i++)
{
sum += (1/i);
}
printf("%lf\n",sum);
return 0;
}