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; +} +