大整數相乘

2021-06-13 13:23:12 字數 1753 閱讀 1316

一、乘數和被乘數為long型別的

public class bignumberchenglong

int pi1 = new int [getlength(p1)];

int pi2 = new int [getlength(p2)];

//將乘數和被乘數存入陣列中

long temp = p1;

int num = 0;

int i = 0;

while (temp > 0)

temp = p2;

i = 0;

while (temp > 0)

//計算

temp = 0; //臨時結果

int step = 0;//進製

int time = 0;//次數

int bit = 0;//位數

for(int j:pi1)while (temp > 9);

}else

time ++;

} bit ++;

} system.out.println("***************************************");

int length = result.length - 1;

while(result[length] == 0)

for(int j = length; j >= 0; j --)

system.out.print(result[j]);

} system.out.println();

system.out.println("***************************************");

} //獲得long型別的長度

private static int getlength(long temp)

return i;

} }

二、乘數和被乘數是string型別的

public class bignumberchengstring

char ctemp = ' ';

char pc1 = p1.tochararray();

for (int i = 0; i < pc1.length / 2; i++)

char pc2 = p2.tochararray();

for (int i = 0; i < pc2.length / 2; i++)

int temp = 0;//臨時結果

int step = 0;//進製

int time = 0;//次數

int bit = 0;//位數

for (char c1 : pc1) while (temp > 9);

result[time + i] = (char) (temp + ascii);

} else

time++;

} bit++;

} system.out.println("##############################");

system.out.print(p1 + " x " + p2 + " = ");

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

system.out.println();

system.out.println("##############################");

} }

大整數相乘

這是一道經典的上機題目 include include include define n 100 n代表乘數的位數,根據具體應用,想設多大設多大。function 大整數相乘演算法 引數 a 乘數 b 乘數 n a的長度 m b的長度 沒有返回值,結果直接放到全域性變數res陣列中,如果不想要全域性...

大整數相乘

處理大整數相乘的辦法很多,我這裡貼一種最簡單實現,通過字元陣列去接收和輸入大整數。題目要求如下 如下 2015.9.15 華為.cpp 定義控制台應用程式的入口點。include stdafx.h include include define maxlength 1024 define m 100 ...

大整數相乘

輸入的資料有兩行,分別是兩個非負數,最多1000位,輸出它們的乘積 示例 輸入 213897129837128937123 43502789523572345 輸出 9305121819000846375051201723846663435 轉換成10000進製,即用乙個int陣列,每個陣列代表一位...