Try the following:
//------------DEVELOPED BY:Ighit F4YSAL------------- #include<iostream> #include<string> #include<sstream> #define BIG 250 //MAX length input using namespace std; int main(){ int DUC[BIG][BIG*2+1]={0},n0[BIG],n1[BIG],i,t,h,carry=0,res; string _n0,_n1; while(1){ //-----------------------------------get data------------------------------------------ cout<<"n0="; cin>>_n0; cout<<"n1="; cin>>_n1; //--------------------string to int[]---------------------------------------- for(i=_n0.length()-1,t=0;i>=0,t<=_n0.length()-1;i--,t++){ n0[i]=_n0[t]-'0'; } i=0; for(i=_n1.length()-1,t=0;i>=0,t<=_n1.length()-1;i--,t++){ n1[i]=_n1[t]-'0'; } i=0;t=0; //--------------------------produce lines of multiplication---------------- for(i=0;i<=_n1.length()-1;i++){ for(t=0;t<=_n0.length()-1;t++){ res=((n1[i]*n0[t])+carry); carry=(res/10); DUC[i][t+i]=res%10; } DUC[i][t+i]=carry; carry=0; } i=0;t=0;res=0;carry=0; //-----------------------------add the lines------------------------------- for(i=0;i<=_n0.length()*2-1;i++){ for(t=0;t<=_n1.length()-1;t++){ DUC[BIG-1][i]+=DUC[t][i]; //cout<<DUC[t][i]<<"-"; } res=((DUC[BIG-1][i])+carry); carry=res/10; DUC[BIG-1][i]=res%10; //cout<<" ="<<DUC[BIG-1][i]<<endl; } i=0;t=0; //------------------------print the result------------------------------------ cout<<"n1*n0="; for(i=_n0.length()*2-1;i>=0;i--){ if((DUC[BIG-1][i]==0) and (t==0)){}else{cout<<DUC[BIG-1][i];t++;} //cout<<DUC[BIG-1][i]; } //-------------------------clear all------------------------------------- for(i=0;i<=BIG-1;i++){ for(t=0;t<=BIG*2;t++){ DUC[i][t]=0; } n0[i]=0;n1[i]=0; } //--------------------------do it again------------------------------------- cout<<"\n------------------------------------------------\n\n"; } return 0; }
source share