加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

大数乘法

发布时间:2020-12-14 02:55:22 所属栏目:大数据 来源:网络整理
导读:#includeiostreamusing namespace std;#includevectorvoid main(){const int N = 10;const int M = 3;char str1[N] = "922222229";char str2[M] = "22";vectorint myvector1; int weishu = 0;for (int j = 0; j M-1; j++){for (int i = 0; i N - 1; i++){int
#include<iostream>
using namespace std;
#include<vector>
void main(){
	const int N = 10;
	const int M = 3;
	char str1[N] = "922222229";
	char str2[M] = "22";
	vector<int> myvector1;
	 
	int weishu = 0;
		for (int j = 0; j < M-1; j++)
	{
		for (int i = 0; i < N - 1; i++)
		{
			int num = (str1[N - i - 2] - '0') *(str2[M - j - 2] - '0') + weishu;
			weishu = num / 10;
			if (myvector1.size() <= j + i)myvector1.push_back(num%10);
			else{
				myvector1[j + i] += num % 10;
				weishu += myvector1[j + i] / 10;
				myvector1[j + i] = myvector1[j + i] % 10;
			} 
		}
		if (weishu){
			if (myvector1.size() <= N - 1 + j)myvector1.push_back(weishu);
			else{
				myvector1[N - 1 + j] += weishu;
			}
			weishu = 0;
		}
		
	} 
	for (int i = myvector1.size()-1; i >= 0; i--)
	{
		cout << myvector1[i];
	} 
	system("pause");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读