star

搜索

RSS

RSS Link

计数器

140156
达夫的设备

大整数乘法

Star posted @ 2011年7月31日 16:37 in C++ with tags c++ 高精度 , 3221 阅读
#include <iostream>
#include <memory>
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;
	memset(ret, 0, sizeof(int)*size);
	//先把两数组分别相乘 
	for(i = 0; i < size2; ++i)
	{
		int k = i;
		for(int j = 0; j < size1; ++j)
		{
			ret[k++] += num2[i]*num1[j];
		}
	}
	//进位 
	for(i = 0; i < size; ++i)
	{
		if(ret[i] >= 10)
		{
			//加上进位 
			ret[i+1] += ret[i] / 10;
			//只留个位 
			ret[i] %= 10;
		}
	}
	return ret;
}
int main(int argc, char *argv[])
{
	int num1[] = {1,2,3,4,5,6,7,8,9,1,1,1,1,1};
	int num2[] = {1,1,1,2,2,2,3,3,3,4,4,4,5,5};
	int* ret = multi(num1, 14, num2, 14);
	for(int i = 27; i >= 0; i--)
	{
		cout << ret[i];
	}
	delete[] ret;
	return 0;
}

计算11111987654321*55444333222111=616096746266157102781891631

Anonymous 说:
2020年9月14日 05:36

I invite you to the page where     see how much we have in common. 룸알바

Anonymous 说:
2020年9月15日 19:22

Mmm.. estimable to be here in your report or notify, whatever, I repute I should moreover process strong for my have website want I play some salubrious further updated busy in your location. 안전놀이터

Anonymous 说:
2020年9月16日 19:55

Below you will understand what is important, the idea provides one of the links with an exciting site: 홀짝게임

Kar Board Question P 说:
2022年9月30日 14:21

KSEEB Model Paper 2023 Class 9 Pdf Download with Answers for Kannada Medium, English Medium, Hindi Medium, Urdu Medium & Students for Small Answers, Long Answer, Very Long Answer Questions, and Essay Type Questions to Term2 & Term2 Exams at official website.Kar Board Question Paper Class 9 New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter