题解 | #牛牛学数列2#
牛牛学数列2
https://www.nowcoder.com/practice/fc72951f52984f3abd286d82eeffacba
#include <stdio.h> int main() { float n; double sum = 0.0;//如果是float 来定义的话,精度可能不够,所以需要用上double scanf("%f", &n); if (n > 1000 || n < 0) return 0; for (int i = 1; i <= n; i++) { sum += 1.0 / i; } printf("%.6lf", sum); return 0; }