gpt4 book ai didi

c - For循环只运行一次

转载 作者:行者123 更新时间:2023-11-30 20:43:53 24 4
gpt4 key购买 nike

int input;
int factorial;
int half;

printf("Enter the number you wish to calculate: ");
scanf("%d", &input);

for(x=1; x<input; x++);
{
half = input - 1;
factorial = input * half;
}

printf("%d\n", factorial);

return 0;

它运行一次,给我输入数字 *(输入数字 - 1),考试,输入是 5,它给出 20。我做错了什么导致它无法继续运行?

最佳答案

for循环后有一个;。删除它,你就会没事的:

for(x=1; x<input; x++) {
// your stuff
}

您仍然需要修复循环中的另一个错误,如其他答案中所述。

关于c - For循环只运行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14884632/

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