大数乘法(乘数是10以内)(被乘数是sting)

#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
#define MAX 100

char news[MAX]={"4526"};

void mul(int n)
{
	int carry=0;int i;


	//前几位
	for(i=strlen(news)-1;i>0;i--)
	{
		int res=(news[i]-'0')*n+carry;

		//如果有进位
		if(res/10>0)
		{
			int zhen=res/10;
			int yush=res%10;
			news[i]=yush+'0';
			carry=zhen;
		}
		else
		{
			carry=0;
			int yush=res%10;
			news[i]=yush+'0';
		}
	}

	//最后一位
	int res=(news[0]-'0')*n+carry;
	if(res/10>0)
	{
		int zhen=res/10;
		int yush=res%10;

		//存储yush
		news[0]=yush+'0';

		//存储zhen
		int i;
		for(i=strlen(news)-1;i>=0;i--)
		{
			news[i+1]=news[i];
		}
		news[0]=zhen+'0';
	}
	else
	{
		int yush=res%10;
		news[0]=yush+'0';
	}

}
int main()
{
	mul(7);
	return 0;
}

/*
1 整数乘法跟字符串不相同,字符串为456,就是从4开始成,但是如果是int从6开始乘
而且存储的时候也是从6开始存储的。
 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值