一.求一个数的阶乘--n!
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
//一.求一个数的阶乘--n!
int n = 0;
scanf("%d", &n);
int i = 0;
int a = 1;
for (i = 1; i <= n; i++)
{
a *= i;
printf("%d!=%d\n",i,a);
}
return 0;
}
二.求阶乘 1!到n!的总和
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
//第一种办法
/*int n = 0;
scanf("%d", &n);
int i = 0;
int a = 1;
int sum = 0;
for (i = 1; i <= n; i++)
{
a *= i;
printf("%d!=%d\n",i,a);
sum += a;
}
printf("sum=%d\n", sum);*/
//第二种办法
int n = 0;
scanf("%d", &n);
int i =0,j=0;
int a = 1;
int sum = 0;
for (i = 1; i <= n; i++)
{
for (j = 1; i <= n; i++)
{
a *= i;
printf("%d!=%d\n",i,a);
sum += a;
}
printf("sum=%d\n", sum);
}
return 0;
}