2729:求12以内n的阶乘
#include<iostream>
using namespace std;
int main()
{
int n,sum=1;
scanf("%d",&n);
for(int i=1;i<=n;++i)
sum=sum*i;
printf("%d",sum);
return 0;
}
2730:求20以内n的阶乘
#include<iostream>
using namespace std;
int main()
{
int n;
unsigned long long sum=1;
scanf("%d",&n);
for(int i=1;i<=n;++i)
sum=sum*i;
printf("%lld",sum);
return 0;
}
2731:求10000以内n的阶乘
#include<iostream>
using namespace std;
int str[10000005];
int len=1;
void jiecheng(int *p,int i)
{
for(int j=0;j<len;++j)
*(p+j) *=i;
for(int j=0;j<len;++j)
if(*(p+j)>=10)
{
*(p+j+1) +=*(p+j)/10;
*(p+j)=*(p+j)%10;
}
while(p[len]>0)
{
p[len+1]=p[len]/10;
p[len]%=10;
len++;}
}
int main()
{
int n;
str[0]=1;
scanf("%d",&n);
for(int i=1;i<=n;++i)
jiecheng(str,i);
for(int i=len-1;i>=0;i--)
printf("%d",str[i]);
return 0;
}