gpt4 book ai didi

c - for循环一定有错误

转载 作者:行者123 更新时间:2023-11-30 20:32:39 25 4
gpt4 key购买 nike

For some reason this cycle doesn't stop, without the else it doesn't even print the first line and I dont't know how to fix it

    for(int i = 0; prime <= sqrt(rest); ++i) {
printf("%d", i);
if (primes[i] == 1) {
prime = primes[i];
printf("%d", prime);
while (rest % prime == 0) {
rest = rest / prime;
rep++;
}
if (rep == 1) {
printf("%d", i);
print++;
} else if (rep > 1) {
printf("%d^%d", prime, rep);
print++;
}
if (rest != 1 && print != 0) {
printf(" x ");
} else if (print != 0) {
printf("\n");
}
rep = 0;
print = 0;
}else{
printf("WTF\n%d\n", i);
i++;
}
}
if (rest > 1) {
printf("%lld\n", rest);
} else{
printf("WTF\n");
break;
}
}

最佳答案

你永远不会改变素数的值,这就是你的条件被设置为停止的原因,所以如果它永远不会改变,它就永远不会停止。也许你的意思是在 for 循环开始时是 prime 而不是 i ?

关于c - for循环一定有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47191606/

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