c语言 大数乘法,很大的数相乘怎么办?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include&nbsp  

#include&nbsp  

using&nbsp  namespace&nbsp  std;

int&nbsp  main(int&nbsp  argc,&nbsp  char&nbsp  *argv[])

{

&nbsp &nbsp

&nbsp &nbsp long&nbsp  i,j, c,len,temp = 0;

&nbsp &nbsp int&nbsp  n&nbsp  =&nbsp  95123;

&nbsp &nbsp long&nbsp *a=new&nbsp  long[4&nbsp  *&nbsp  n];&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp  //动态分配空间

&nbsp &nbsp a[0]=1;&nbsp  len=1;

&nbsp &nbsp for(i=0;&nbsp  i<12;&nbsp  i++)

&nbsp &nbsp {

&nbsp &nbsp &nbsp &nbsp c=0;

&nbsp &nbsp &nbsp &nbsp for(j= 0;&nbsp j

&nbsp &nbsp &nbsp &nbsp {

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp temp=a[j]* n+c;

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp c= temp/10000;

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp a[j]=temp%10000;

&nbsp &nbsp &nbsp &nbsp }

&nbsp &nbsp &nbsp &nbsp

&nbsp &nbsp &nbsp &nbsp while(c>0)&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp  //处理进位

&nbsp &nbsp &nbsp &nbsp {

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp len = len +1;

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp a[len-1]=c;

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp c/= 100000;

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp a[len - 1]%=10000;

&nbsp &nbsp &nbsp &nbsp }

&nbsp &nbsp }

&nbsp &nbsp printf( "%ld ",&nbsp  a[len-1]);

&nbsp &nbsp for(i=len-2;&nbsp  i>=0; i--)&nbsp &nbsp &nbsp  //逆序输出

&nbsp &nbsp &nbsp &nbsp printf( "%04ld ",&nbsp  a[i]);&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp

&nbsp &nbsp

&nbsp &nbsp delete&nbsp  a;&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp  //释放空间

&nbsp &nbsp

&nbsp &nbsp system( "PAUSE ");

&nbsp &nbsp return&nbsp  0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值