輸入的資料有兩行,分別是兩個非負數,最多1000位,輸出它們的乘積
示例:
輸入:
213897129837128937123
43502789523572345
輸出:
9305121819000846375051201723846663435
轉換成10000進製,即用乙個int陣列,每個陣列代表一位數,按10000進製計算
#include
#include
#include
#include
#define n 1010
#define base 10000
using
namespace
std;
int a[500], b[500], ans[50002];
char s1[1010], s2[1010];
int main()
if (i < 3)
a[j++] = t;
}//字串轉換成int陣列
l1 = j;
for (j = 0, i = l2-1; i >= 3; i -= 4, j++)
if (i < 3)
b[j++] = t;
}l2 = j;
for (j = l1; j >= 0; j--)
memset(ans, 0, sizeof(ans));
carry = 0;//進製
for (i = 0; i < l1; i++)
ans[i+j] += carry;
}for (j = 50000; j >= 0; j--)
printf("%d", ans[j]);
for (j--; j >= 0; j--)
return
0;}
大整數相乘
一 乘數和被乘數為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...
大整數相乘
這是一道經典的上機題目 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 ...