//利用字符數組存儲64位的乘數和被乘數,然后返回乘值
#include<stdio.h> #include<string.h>
int main() { char s1[65],s2[65]; int res[130]; scanf("%s%s",s1,s2); int i,j,len1,len2; len1 = strlen(s1); len2 = strlen(s2); //初始化res為0
memset(res,0,sizeof(res)); //兩數相乘的結果放在res中
for(i=0;i<len1;i++){ for(j=0;j<len2;j++){ res[i+j+1] += (s1[i]-'0')*(s2[j]-'0'); } } //處理進位,從數字低位開始
for(i=len1+len2-1;i>0;i--){ if(res[i]>=10){ res[i-1] += res[i]/10; res[i] = res[i]%10; } } i=0; while(res[i]==0) i++; for(;i<len1+len2;i++) printf("%d",res[i]); return 0; }