You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
298 B
19 lines
298 B
1 year ago
|
#include <stdio.h>
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|