10的阶乘:10! = 12345678910 = 3628800
事情台-代码
#include <iostream>

using namespace std;
int main()
{
//10的阶乘:10! = 123...8910 = 3628800
//定义结果默认值定义为 1不可为 0。
int total = 1;
//利用for循环办法打算结果
for(int i = 1; i <=10; i++)
{
// 普通写法
//total = total i;
// 简写
total = i;
}
//打印输出打算10的阶乘 10!
cout << "for循环打算10的阶乘:10! = " << total << "\n";
//定义结果默认值定义为 1不可为 0。
total = 1;
//定义循环次数
int i = 10;
//利用while循环办法打算结果
while(i > 0)
{
total = i;
i--;
}
//打印输出打算10的阶乘 10!
cout << "while循环打算10的阶乘:10! = " << total << "\n";
//按任意键退出
system("pause");
return 0;
}
运行结果如下:
for循环打算10的阶乘:10! = 3628800
while循环打算10的阶乘:10! = 3628800