8 回答
TA贡献1794条经验 获得超8个赞
var sum = 0;
for(var i = 0;i<=i;i++){
if(sum >= 100){
break;
}else{
sum += i;
}
}
console.log('i =' +(i-1)); //i = 14
console.log('sum = '+sum); //sum = 105
TA贡献1906条经验 获得超10个赞
function a(count){
var sum =0;
for(var i=1;i<count;i++){
if(sum >count){
console.log(i-1);
break;
}
sum +=i;
}
}
a(100);//求累加值刚好超过100,参数传100,求累加值刚好超过1000,参数传1000,
TA贡献1799条经验 获得超6个赞
var sum = 0;
for (var i = 0; sum <= 100; i++) {
sum += i;
}
console.log(sum);
console.log(i-1);
TA贡献1943条经验 获得超7个赞
function xx(){
var sum=0;
var n=0;
for(;;){
if(sum<=100){
n++;
sum+=n;
console.log(n);
}else{
console.log(n);
return n;
}
}
}
xx();
TA贡献1801条经验 获得超8个赞
var sum = 0;
for (var i = 1; sum <= 100; i++) {
sum += i;
}
console.log(sum);
console.log(i);
TA贡献1858条经验 获得超8个赞
var a=1;
var sum=0;
while(sum<=100){
a++;
sum+=a;
}
console.log(sum);
console.log(a);
TA贡献1911条经验 获得超7个赞
var n = 0;
for(var i = 1; i<=100;i++){
if(n<=100){
n = i+n;
console.log(n) //105
console.log(i); //14
}
}
TA贡献1829条经验 获得超7个赞
function a(v) {
for (let i = 0; i < i + 1; i++) {
v -= i;
if (v <= 0) {
console.log(i - 1);
break;
}
}
}
a(100);
添加回答
举报