void stringPlus(char *nums,int last,int plus)//plus 0~81
{
int flag = 0;
while(plus)
{
if(nums[last]-'0' + plus%10 + flag > 9)//进位
{
nums[last] = nums[last] + plus%10 + flag - 10;
flag = 1;
}
else
{
nums[last] = nums[last] + plus%10 + flag;
flag = 0;
}
plus = plus / 10;
last--;
}
while(flag)
{
if(nums[last]-'0' + plus%10 + flag > 9)//进位
{
nums[last] = nums[last] + plus%10 + flag - 10;
flag = 1;
}
else
{
nums[last] = nums[last] + plus%10 + flag;
flag = 0;
}
last --;
}
}
char* multiply(char* num1, char* num2) {
int MAX_LEN=230;
char* ans = (char *)malloc(sizeof(char)*MAX_LEN);
for(int i = 0;i!=MAX_LEN-1;++i)
ans[i]='0';
if(num1[0]=='0'||num2[0]=='0')
{
ans[1]='\0';
return ans;
}
ans[MAX_LEN-1]='\0';
int last = MAX_LEN-2;
int index = 0;
long long sum = 0;
for(int i = strlen(num1)-1;i>=0;--i)
{
int plus = 0;
last = MAX_LEN - (strlen(num1)-1 - i) - 2;
for(int j = strlen(num2)-1;j>=0;--j)
{
plus = (num1[i]-'0')*(num2[j]-'0');
stringPlus(ans,last,plus);
last--;
}
}
while(*ans=='0')
ans++;
return ans;
}
来源:CSDN
作者:小狗巴士
链接:https://blog.csdn.net/xx337881648/article/details/81981838