From eae410f7773c0ce01e919bb0a62b81cc31f526e6 Mon Sep 17 00:00:00 2001 From: flykhan Date: Sat, 24 Jun 2023 10:23:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=87=BA=E4=B8=80=E4=B8=AA=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=98=B6=E4=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day7/homework/oh2.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 day7/homework/oh2.cpp diff --git a/day7/homework/oh2.cpp b/day7/homework/oh2.cpp new file mode 100644 index 0000000..7184e5a --- /dev/null +++ b/day7/homework/oh2.cpp @@ -0,0 +1,22 @@ +// 输入一个整数,输出它的阶乘。 +// 例如:输入5,输出120 +#include + +using namespace std; + +int main() +{ + int n; + int sum = 1; + cout << "请输入一个整数:"; + cin >> n; + + while (n) + { + sum *= n; + --n; + } + cout << sum << endl; + + return 0; +} \ No newline at end of file