cella @ 2020-10-02 10:11:08
#include<iostream>
using namespace std;
int n;
int jinbi(int k){
int a=1,b=1;
for(int i=i;i<k;i++){
for(int j=1;j<=i;j++){
if(b>=k){
return a;
}else{
b++;
a+=i;
}
}
}
}
int main() {
cin>>n;
int y=jinbi(n);
cout<<y;
return 0;
}
by cella @ 2020-10-02 10:14:00
刚刚改了一下for循环里的i=1写成i=i了,看看还有什么问题
by sheeplittlecloud @ 2020-10-02 10:19:26
@Cece159357 你还要i++
by sheeplittlecloud @ 2020-10-02 10:21:11
@Cece159357 再说过不了就别用函数嘛,只用2个while不也可以解决
by cella @ 2020-10-02 10:28:07
谢谢
by cella @ 2020-10-02 10:34:04
纠正了,可是用数据6输出的是16
#include<iostream>
using namespace std;
int n=0;
int main() {
cin>>n;
int a=1,b=1;
for(int i=1;i<n; i++) {
for(int j=1; j<=i; j++) {
if(b>=n) {
cout<<a;
break;
} else {
a+=i;
b++;
i++;
}
}
}
return 0;
}
by supermanf @ 2020-11-24 22:41:28
#include<stdio.h>
int main()
{
double sum=0;
int n,i,t;
int counter;
scanf("%d",&n);
for(i=1,counter=0;1;i++)
{
for(t=1;t<=i;t++)
{
sum=sum+i;
counter++;
}
if(counter==n)
{
printf("%.0f",sum);
break;
}
}
return 0;
}
by supermanf @ 2020-11-24 22:42:13
大佬们看看,为什么我的有限制条件
by shiweihao123 @ 2020-12-30 16:46:51
你个憨憨全错了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!