整数高精度乘法
2013-09-26 23:08
260 查看
#include <iostream> #include <string> using std::cin; using std::cout; using std::endl; #define MAX 100 int main(int argc, const char * argv[]) { // insert code here... long long m,n; int a[MAX],b[MAX],c[MAX],la,lb,len; len = 0; cin>>m>>n; la = 0; while(m>0) { a[++la] = m % 10; m = m / 10; } lb = 0; while(n>0) { b[++lb] = n % 10; n = n / 10; } memset(c, 0, sizeof(c)); len = la + lb; for(int i = 1;i<= la;++i) for(int j = 1;j<=lb;++j) c[i+j-1] = c[i+j-1]+a[i]*b[j]; cout<<"============================="<<endl; for(int i=1;i<=len;i++) { cout<<c[i]<<endl; } cout<<"============================="<<endl; for(int i=1;i<=len;i++) { c[i+1]=c[i+1]+c[i]/10; c[i]=c[i]%10; } for(int i=1;i<=len;i++) { cout<<c[i]<<endl; } cout<<"============================="<<endl; while(c[len]==0) len--; m=c[len]; while(m>0) { c[len]=m%10; m=m/10; len++; } cout<<"============================="<<endl; for(int i=len-1;i>=1;i--) {cout<<c[i];} cout<<endl; return 0; }
相关文章推荐
- 【CodeVS 3123】 高精度练习之超大整数乘法
- 用python写高精度的数据乘法,要求输入的书不大于256的正整数,计算其结果
- 【CodeVS 3123】 高精度练习之超大整数乘法
- 大整数乘法(高精度)
- 3123 高精度练习之超大整数乘法 - Wikioi
- BZOJ 1263 [SCOI2006]整数划分 - 高精度乘法
- 【vijos1033】【数值/数论】【高精度乘法】整数分解(版本2)
- 【快速傅里叶变换】【FFT】【WikiOI】【P3132】【高精度练习之超大整数乘法】
- CODEVS 3123 高精度练习之超大整数乘法
- 任意长度的高精度大整数和浮点数的加法和乘法
- 整数高精度运算的库(加法,减法,乘法,除法,取模)
- POJ 1001 解题报告 高精度大整数乘法模版
- 超大整数乘法模板(高精度乘以低精度)
- POJ 1001 解题报告 高精度大整数乘法模版
- 高精度计算-大整数乘法
- 【高精度计算 02】 大整数乘法
- 高精度(正整数的加、减、乘法)
- 【CodeVS 3123】高精度练习之超大整数乘法 &【BZOJ 2197】FFT快速傅立叶
- codevs 3123 高精度练习之超大整数乘法
- cv3123 高精度练习之超大整数乘法(FFT)