-
-
Save kurimulion/9447990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(void){ | |
int a,j,i,num1[300]={0},n,temp; | |
scanf("%d",&n); | |
num1[0]=1; | |
for(i=1;i<=n;i++){ | |
for(a=299;a>=0;a--) | |
if(num1[a]!=0) | |
break; //檢查運算所占用到的索引值 -1 | |
for(j=0;j<=a;j++) | |
num1[j]=num1[j]*i; //從1乘到第n項 | |
for(j=0;j<=a;j++){ | |
if(num1[j]>=10 && num1[j]<100){ | |
temp=num1[j]; | |
num1[j]=temp%10; | |
num1[j+1]=num1[j+1]+temp/10; | |
} //乘完後做進位,曾嘗試把它放在前一個迴圈中,但似乎會出現一點小問題 Option1當索引值中的數大於等於10小於100時的情況 -2 | |
else if(num1[j]>=100){ | |
temp=num1[j]; | |
num1[j]=temp%10; | |
num1[j+1]=num1[j+1]+(temp/10)%10; | |
num1[j+2]=num1[j+2]+temp/100; | |
} //同上 Option2當索引值中的數大於100時的情況 -3 | |
} //控制階乘次數 | |
for(a=299;a>=0;a--) | |
if(num1[a]!=0) | |
break; //檢查運算所占用到的索引值 | |
} | |
for(;a>=0;a--) | |
printf("%d",num1[a]); //輸出計算後的值 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment