# 高精度乘法

1
2

2

1.进位问题

if (c[i] > 9)//进位
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}


2.去除前面输出的0

while( c[len] == 0 && len > 1)//去除前面多余的0
len--;


(注：本人小白，如有错误，请指正，谢谢）

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
string num1, num2;
cin >> num1 >> num2;
int a[10000] = { 0 }, b[10000] = { 0 }, c[10000] = { 0 };
if (num1.size() < num2.size())
swap(num1, num2);
//倒序存储
for (int i = 1;i <= num1.size();i++)//将字符串转换为数字存入数组中
{
a[i] = num1[num1.size() - i] - '0';
}
for (int i = 1;i <= num2.size();i++)
{
b[i] = num2[num2.size() - i] - '0';
}
int len1, len2;
len1 = num1.size();
len2 = num2.size();
int len = len1 + len2;
for (int i = 1;i <= len1;i++)
{
for (int j = 1;j <= len2;j++)
{
c[i + j -1] += a[i] * b[j];//按乘法

}
}
for (int i =1;i < len;i++)
{
if (c[i] > 9)//进位
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
}
while( c[len] == 0 && len > 1)//去除前面多余的0
len--;
for (int i =len;i >= 1;i--)//倒序输出
{
cout << c[i];
}
}


11-03 6833
12-15 1万+

08-19 1万+
04-18 2535
07-16 46
07-14 5955
07-26