输出一个数的阶乘
This commit is contained in:
parent
5434ce3192
commit
eae410f777
22
day7/homework/oh2.cpp
Normal file
22
day7/homework/oh2.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// 输入一个整数,输出它的阶乘。
|
||||
// 例如:输入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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user