题解 | #牛牛学数列2#
牛牛学数列2
http://www.nowcoder.com/practice/fc72951f52984f3abd286d82eeffacba
#include<stdio.h>
int main() {
double val;
int n;
scanf("%d", &n);
if (n >= 0 && n <= 1000) {
for (int i = 1; i <= n; i++) {
val += 1.0 / i;
}
printf("%.6f", val);
}
return 0;
}
int main() {
double val;
int n;
scanf("%d", &n);
if (n >= 0 && n <= 1000) {
for (int i = 1; i <= n; i++) {
val += 1.0 / i;
}
printf("%.6f", val);
}
return 0;
}