求教:这个程序在用 DEV debug时,有死循环,执行时不会出现死循环。。。
//大整数乘法(传统法)//用string类 元素之间无法相乘
#include<iostream>
#include<string>
using namespace std;
int b1 = 0;
int max1 = 0;
int index = -1;
int main(){
string s1, s2, s3, s4;
int a[210] = {0}, b[210] = {0}, c[40010] = {0}, d[40010] = {0};
cin >> s1 >> s2;
int i = 0, j = 0 ;
i = s1.length();
j = s2.length(); //字符转数字。字符串类字符不能运算
for(int t = 0; t < i; t++){
s1[t] -= 48;
a[t+1] = s1[t];
}
for(int t = 0; t < j; t++){
s2[t] = s2[t] - 48;
b[t+1] = s2[t];
}
while(j > 0){
index++;
int z = 0;
d[40010] = {0};
b1 = 0;
i = s1.length();
for(int l = 0; l < index; l++){
d[z] = 0;
z++;
}
while(i+1 > 0){ //因为进位,第一位元素定义为0
d[z++] = (a[i]*b[j] + b1)%10;
b1 =(a[i--]*b[j--])/10;
}
if(max1 < z){
max1 = z;
}
int b2 = 0;
for(int k = 0; k < z+1; k++){
c[k] = (c[k] + d[k] + b2)%10;
b2 = (c[k] + d[k])/10;
}
}
if(c[max1] != 0){
for(int i = 0; i < max1 + 1; i++){
cout << c[max1-i];
}
}
else{
for(int i = 0; i < max1; i++){
cout << c[max1-i-1];
}
}
return 0;
}