各项和S应为double类型
#include<stdio.h>
int main() {
int k;
scanf("%d", &k);
double s = 0;
int n = 1; //这里的n用float结果.out是0,amusing!!!
while (s <= k) {
s += 1.0 / n;
n++;
}
//n++;
printf("%d", n-1);
return 0;
}
各项和S应为double类型
#include<stdio.h>
int main() {
int k;
scanf("%d", &k);
double s = 0;
int n = 1; //这里的n用float结果.out是0,amusing!!!
while (s <= k) {
s += 1.0 / n;
n++;
}
//n++;
printf("%d", n-1);
return 0;
}