From 9f7815ba9a5a248df0db37d61f7c8b88f6c45f16 Mon Sep 17 00:00:00 2001 From: p9xkyljec <1412687891@qq.com> Date: Fri, 27 Oct 2023 16:01:14 +0800 Subject: [PATCH] ADD file via upload --- main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d055824 --- /dev/null +++ b/main.cpp @@ -0,0 +1,18 @@ +#include + +int factorial(int n) { + int result = 1; + for (int i = 1; i <= n; i++) { + result *= i; + } + return result; +} + +int main() { + int n; + printf("请输入一个非负整数:"); + scanf("%d", &n); + printf("%d! = %d\n", n, factorial(n)); + return 0; +} +