1.求n的阶乘
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
int n = 0;
int result = 1;
printf("请输入一个数:");
scanf("%d", &n);
for (int i = 1; i <= n; i++){
result *= i;
}
printf("阶乘为:%d\n", result);
system("pause");
return 0;
}
2、计算1!+2!+3!+……+10!
#include<stdio.h>
#include<stdlib.h>
int fact(n){
int result = 1;
for (int i = 1; i <= n; i++){
result *= i;
}
return result;
}
int main()
{
int sum = 0;
for (int j = 1; j <= 10; j++){
sum += fact(j);
}
printf("%d\n", sum);
system("pause");
return 0;
}