// 大整数问题
void BigInt(int *pNum1, int size1, int *pNum2, int size2, int *pRet)
{
if(pRet == NULL)
return;
memset(pRet, 0, sizeof(int) * (size1 + size2));
for(int i = 0; i < size2; i++)
{
int k = i;
for(int j = 0; j < size1; j++)
{
pRet[k++] += pNum1[j] * pNum2[i];
}
}
for(int i = 0; i < (size1+size2); i++)
{
if(pRet[i] >= 10)
{
pRet[i+1] += pRet[i] / 10;
pRet[i] %= 10;
}
}
}
void TestBigInt()
{
int num1[] = {1,0}; // 01
int num2[] = {3,2}; // 23
int *pRet = new int[4];
BigInt(num1,2,num2,2,pRet);
for(int i = 3; i >=0; i--)
{
cout << pRet[i];
}
delete [] pRet;
}
大整数
最新推荐文章于 2023-04-15 22:55:44 发布