大整數乘法

2021-07-22 18:03:53 字數 612 閱讀 8522

輸入為兩個100位以內大整數,輸出其結果

例程:輸入:1234567 123

輸出:151851741

本題思想為:用字串儲存其各位字元,以數學乘法基本計算方法進行相乘進製運算,得出最終結果。

#include

#include

#include

#include

using namespace std;

int main()

strmid[i+j+1]=temp+'0';

strrst[wei2-1-i]=strmid;//strcmp(strrst[wei2-1-i],strmid);//儲存一次乘積結果

}for(int j=wei1+wei2-1; j>=0; j--)

strlastrst[j]=temp%10+'0';//並將和的個位存入相應位,十位進製進行下一步運算

temp=temp/10;

}int x=0;

while(strlastrst[x++] == '0');//避免輸出最高位為0的情況

x--;

while(strlastrst[x] != '\0')

cout

}

大整數乘法

參考 http hi.baidu.com operationsystem blog item 6e45dd1af1acadf3ae51330b.html 在計算機中,長整型 long int 變數的範圍是 2147483648 至 2147483647,因此若用長整型變數做乘法運算,乘積最多不能超過...

大整數乘法

問題描述 by 計算機演算法設計與分析 王曉東 p17 通常,在分析乙個演算法的計算複雜性時,都將加法和乘法運算當作是基本運算來處理,即將執行一次加法或乘法運算所需的計算時間當作乙個僅取決於計算機硬體處理速度的常數。這個假定僅在計算機硬體能對參加運算的整數直接表示和處理時才是合理的。然而,在某些情況...

大整數乘法。

include using namespace std int multi int num1,int size1,int num2,int size2 int size size1 size2 int ret new int size int i 0 for i 0 iret i 0 for i 0...