C语言程序运行问题
c吧
全部回复
仅看楼主
level 1
程序:#include<stdio.h>
int main(){
for(int i=1;i<=1000;i++){
int temp=0;
again:
for(int j=1;j<i;j++){
if(i%j==0&&temp==i+1)printf("%d ",j);
else if(i%j==0)temp+=j;
}
if(temp==i){
printf("\n%d its factors are ",i);
temp++;
goto again;
}
}
return 0;
}
运行结果:6 its factors are 1 2 3
28 its factors are 1 2 4 7 14 18
496 its factors are 1 2 4 8 16 31 62 124 248
为什么会在28的因数中出现18。
我是用temp=i+1用于控制输出因数,temp<=i时用于判断i是否是完数,检查了好几遍问了一圈ai后都只会回答我不要用goto
2025年11月17日 09点11分 1
level 1
有人吗,教教孩子吧[泪]
2025年11月17日 09点11分 2
level 5
跟着调试器走一遍就行了
i=36、j=18的时候temp=37满足条件输出了。
所以你要实现什么效果🤔
2025年11月17日 12点11分 3
发楼下了,这个调试器是怎么调出来的,可以教一下吗
2025年11月17日 12点11分
本来是想省一个变量来着,结果忽视了temp大于i的情况,看来一个变量还是只干一件事更合理
2025年11月17日 12点11分
而且这么看来ai是真不靠谱,gpt和deepseek问了一圈都没有找出问题在哪里
2025年11月17日 13点11分
@贴吧用户_716aV89 你用什么编译器就用他的调试器呗,你用mingw那就用gdb命令调试。
2025年11月17日 13点11分
level 5
2025年11月17日 12点11分 5
level 1
2025年11月17日 12点11分 6
level 4
建议不要用go to
2025年11月20日 04点11分 7
1