C 超長正整數運算

2021-06-09 01:06:02 字數 1503 閱讀 8263

文字檔案1.txt和2.txt分別儲存超長正整數,然後讀取兩個數進行加法、減法、乘法運算,**如下:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.io;

using system.collections;

namespace count

/// /// 檔案處理

///

///

public static stringbuilder fileoperation()

}if (a.length < b.length)

}arr[0] = bu1;

arr[1] = bu2;

return arr;

}/// /// 加法

///

public static void plus()

else

if (c > 9)

else

count = 1;

}else

}stringbuilder result = new stringbuilder();

for (int i = plusresult.length; i > 0; i--)

file.writealltext("加_lcl.txt", convert.tostring(result), encoding.default);

}/// /// 減法

///

public static void reduce()

if (a - b < 0)

else

}stringbuilder result = new stringbuilder();

for (int i = reduceresult.length; i > 0; i--)

file.writealltext("減_lcl.txt", convert.tostring(result), encoding.default);

}/// /// 乘法

///

public static void multiply()

for (int i = 0; i < otherlength; i++)

for (int i = otherlength - 1; i >= 0; i--)

}stringbuilder builder = new stringbuilder();

for (int i = 0; i < resultlength; i++)

string result = builder.tostring();

if (result.startswith("0"))

file.writealltext("乘_lcl.txt", result.tostring(), encoding.default);}}

}

超長正整數相加

請設計乙個演算法完成兩個超長正整數的加法。輸入引數 string addend 加數 string augend 被加數 返回值 加法結果 思路 兩個數相加,可先將兩個數長度對齊,短的用0補齊後再計算。兩個數相加的結果長度至多為較大的數長度加1。可以用乙個陣列來存放結果。public class m...

超長正整數相加

請設計乙個演算法完成兩個超長正整數的加法。介面說明 輸入引數 string addend 加數 string augend 被加數 返回值 加法結果 public string addlonginteger string addend,string augend 輸入描述 輸入兩個字串數字 輸出描述...

超長正整數的加法

問題描述 編寫程式實現兩個超長正整數 每個最長80位數字 的加法運算。輸入形式 從鍵盤讀入兩個整數,要考慮輸入高位可能為0的情況 如00083 第一行是超長正整數a 第二行是超長正整數b 輸出形式 1.用字串輸入兩個超長整數,分別存放在兩個字串中,每一位對應乙個字串中的字元。2.以較短的超長整數為基...