函数题:10
void Print_Factorial(const int N)
{
if(N<0||N>1000)
{
printf("Invalid input");
return;
}
int arr[3000]={};
arr[0]=1;
int arrLen=1;
int factor=2;
for(;factor<=N;factor++)
{
int j;
int carry=0;
int multiplied;
int calcDigit;
for(j=0;j<arrLen;j++)
{
multiplied=arr[j]*factor;
calcDigit=multiplied%10+carry%10;
carry=carry/10+multiplied/10;
if(calcDigit>=10)
{
carry=carry+calcDigit/10;
calcDigit%=10;
}
arr[j]=calcDigit;
if(j>=arrLen-1&&carry>0)
arrLen++;
}
}
int i;
for(i=arrLen-1;i>=0;i--)
{
printf("%d",arr[i]);
}
}

posted on 2025-03-28 23:04  Swishy  阅读(7)  评论(0)    收藏  举报