编写一个程序,从键盘输入n,然后计算并输出1~n之间所有数的阶乘值。
#include<stdio.h>
int main(){
int i,n;long p=1;
printf("please enter n:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
p=p*i
printf("%d! =%1d\n",i,p);/* 输出1~n之间的所有数的阶乘值 */
}
}
程序的运行结果如下:
Please enter n:10
1!=1
2!=2
3!=6
4!=24
......
知识点:累乘求积的递推公式
i!=(i-1)*i