用c语言函数实现: 计算并输出2的阶乘,6的阶乘,10的阶乘的值
时间: 2024-05-30 21:15:52 浏览: 57
C语言编程,1-10的阶乘
#include<stdio.h>
int factorial(int n) {
int result = 1;
for(int i=1; i<=n; i++) {
result *= i;
}
return result;
}
int main() {
int num1 = 2, num2 = 6, num3 = 10;
printf("%d的阶乘为%d\n", num1, factorial(num1));
printf("%d的阶乘为%d\n", num2, factorial(num2));
printf("%d的阶乘为%d\n", num3, factorial(num3));
return 0;
}
阅读全文