我只知道求左边第n项的和,但给了和求n不会。求大佬解答
function foo(n) {
if (n == 1) {
return 1000 / 1;
} else {
console.log(n);
return 1000 / n + foo(n - 1);
}
}
document.write(foo(100));
js运算会精度缺失,加起来会有问题1000/3这种。。。。
function sum(num,n) {
if ( n <= 1 ) {return 1000};
return num/n+sum(1000,n-1);
}
var total = 10000;
var index = 1
function foo() {
if(total = 0) {
return total;
}else {
total = total - 1000/index;
index ++;
foo();
}
}