Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于C+中的循环结果0+; 我是一个C++新手,两个星期前我开始学习C++中的编码。为什么我下面的代码在构建和运行时总是给我结果0?请帮忙 # include <iostream> # include <string> using namespace std; int main () { int input = 1; cout << "input your number : \n"; cin >> input; int faktorial = 1; for(int i=1;i<=input;i++) { faktorial = faktorial * i; } cout << "factorial value from number " << input << " is " << faktorial << endl; } #包括 #包括 使用名称空间std; int main() { int输入=1; cout>输入; int faktorial=1; 对于(inti=1;i_C++_Loops_For Loop - Fatal编程技术网 输入; int faktorial=1; 对于(inti=1;i,c++,loops,for-loop,C++,Loops,For Loop" /> 输入; int faktorial=1; 对于(inti=1;i,c++,loops,for-loop,C++,Loops,For Loop" />

对于C+中的循环结果0+; 我是一个C++新手,两个星期前我开始学习C++中的编码。为什么我下面的代码在构建和运行时总是给我结果0?请帮忙 # include <iostream> # include <string> using namespace std; int main () { int input = 1; cout << "input your number : \n"; cin >> input; int faktorial = 1; for(int i=1;i<=input;i++) { faktorial = faktorial * i; } cout << "factorial value from number " << input << " is " << faktorial << endl; } #包括 #包括 使用名称空间std; int main() { int输入=1; cout>输入; int faktorial=1; 对于(inti=1;i

对于C+中的循环结果0+; 我是一个C++新手,两个星期前我开始学习C++中的编码。为什么我下面的代码在构建和运行时总是给我结果0?请帮忙 # include <iostream> # include <string> using namespace std; int main () { int input = 1; cout << "input your number : \n"; cin >> input; int faktorial = 1; for(int i=1;i<=input;i++) { faktorial = faktorial * i; } cout << "factorial value from number " << input << " is " << faktorial << endl; } #包括 #包括 使用名称空间std; int main() { int输入=1; cout>输入; int faktorial=1; 对于(inti=1;i,c++,loops,for-loop,C++,Loops,For Loop,您的代码可以工作: 我怀疑您的问题是,您正在查看程序退出代码。当您不从main返回任何值时,程序退出代码为0(这是一种特殊情况,并且只有非无效函数,您可以在其中省略return语句),这通常意味着成功(根据惯例,非零退出代码通常表示某种错误) 试着从IDE中找到程序输出,它应该有正确的打印输出。你的输入是什么??没有;输入6我得到720(检查命令行)。请提供一个。在交互式输入的情况下,这意味着提供输入值。很好的猜测,让我们看看OP是否确认。我添加了return 0;它有效,谢谢lot@dough

您的代码可以工作:

我怀疑您的问题是,您正在查看程序退出代码。当您不从
main
返回任何值时,程序退出代码为0(这是一种特殊情况,并且只有非无效函数,您可以在其中省略return语句),这通常意味着成功(根据惯例,非零退出代码通常表示某种错误)


试着从IDE中找到程序输出,它应该有正确的打印输出。

你的
输入是什么?
?没有;输入6我得到720(检查命令行)。请提供一个。在交互式输入的情况下,这意味着提供输入值。很好的猜测,让我们看看OP是否确认。我添加了return 0;它有效,谢谢lot@doughstone-如果是答案,你应该接受。