qfedu-basic-level/day7/homework/oh2.cpp

22 lines
315 B
C++
Raw Permalink Normal View History

2023-06-24 10:23:45 +08:00
// 输入一个整数,输出它的阶乘。
// 例如输入5输出120
#include <iostream>
using namespace std;
int main()
{
int n;
int sum = 1;
cout << "请输入一个整数:";
cin >> n;
while (n)
{
sum *= n;
--n;
}
cout << sum << endl;
return 0;
}