gpt4 book ai didi

c - 使用 c 的 Spoj 中的运行时 NZEC 错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:48 24 4
gpt4 key购买 nike

这是我解决生命、宇宙和一切问题的代码。它在 SPOJ 中显示运行时 NZEC 错误,尽管它已返回 0。请帮我解决这个问题。

#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
while(1)
{
scanf("%d",&i);
if(i!=42)
printf("%d/n",i);
else
exit(1);
}
return 0;
}

最佳答案

它显示 NZEC(非零退出代码),因为您返回 1(来自 exit(1))而不是 0。

正确的做法是:

#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
while(1)
{
scanf("%d",&i);
if(i!=42)
printf("%d/n",i);
else
return 0; // or you could simply write "break;" here
}
return 0; // This statement won't get executed anyway
}

关于c - 使用 c 的 Spoj 中的运行时 NZEC 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24840760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com