大整數加法

2021-06-23 08:54:27 字數 1081 閱讀 3204

/*大整數加法

描述求兩個不超過200位的非負整數的和。

輸入有兩行,每行是乙個不超過200位的非負整數,可能有多餘的前導0。

輸出一行,即相加後的結果。結果裡不能有多餘的前導0,

即如果結果是342,那麼就不能輸出為0342。

樣例輸入

22222222222222222222

33333333333333333333

樣例輸出

55555555555555555555

*/#include

#include

#include

using

namespace std;

//列印大整數的程式,不能最打出前面的0

void

printbigint1

(char

*number)

if(i==nlength)

else

return;}

char

*add

(const

char

*number1,

const

char

*number2)

else

jinwei=0;

number3[index3]

= bit3+

'0';

}for

(;index1>=

0;index1--,index3--)

else

jinwei=0;

number3[index3]

= bit3+

'0';

}for

(;index2>=

0;index2--,index3--)

else

jinwei=0;

number3[index3]

= bit3+

'0';

} number3[index3]

= jinwei+

'0';

return number3;

}int

main

()

大整數加法

include include include include define debug void plus char char char int is valid char void reverse char int main int argc,char argv up loop 0 strcpy...

大整數加法

方法 這裡用了資料結構棧,實際上棧更方便實現高精度加法。步驟 1 第乙個資料加數按輸入順序 高位到低位 入棧1。此時棧頂為最低位 2 第二個資料加數按輸入順序 高位到低位 入棧2。此時棧頂為最低位 3 將棧1 棧2均pop出棧頂做加法,並考慮進製,結果入棧3,這時棧3正好是低位入棧。4 處理多餘的棧...

大整數加法

include include include define max len 200 int an1 max len 10 int an2 max len 10 char szline1 max len 10 char szline2 max len 10 int main bool bstarto...