昨天晚上看到的一道题目:
The factorial(阶乘) of an integer n,written n!,is the product of the consecutive integers 1 through n.For example,5 factorial is calculated as
5!=5*4*3*2*1=120
Write a program to generate and print a table of the first 10 factorials。
想了半天都没有结果,请高手指教。这个是我自己写的代码。
#include <stdio.h>
main()
{
int n,i;
long int s;
printf(" n________s\n");
for(n=1;n<=10;n++)
{
for (i=1;i<=n;i++)
{
s=i;
s=s*i;
printf(" %d %d\n",n,s);
}
}
return 0;
}