Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- string num1,num2,emp="",num3,num4;
- int t,i,l_num1,l_num2,carry=0,j,sum;
- cin>>t;
- for(i=1; i<=t; i++)
- {
- cin>>num1>>num2;
- num3=num1;num4=num2;
- if(num1.length()>num2.length())
- swap(num1,num2);
- l_num1=num1.length();
- l_num2=num2.length();
- //reverse(num1.begin(),num1.end());
- for (int b=0;b<l_num1/2;b++)
- swap(num1[b],num1[l_num1-b-1]);
- //reverse(num2.begin(),num2.end());
- for (int b=0;b<l_num2/2;b++)
- swap(num2[b],num2[l_num2-b-1]);
- for(j=0; j<l_num1; j++)
- {
- sum=((num1[j]-48)+(num2[j]-48)+carry);
- emp.push_back(sum%10+48);
- carry=sum/10;
- }
- for (int u=l_num1;u<l_num2;u++)
- { int sum = ((num2[u]-48)+carry);
- emp.push_back(sum%10+48);
- carry=sum/10;
- }
- if(carry)
- {emp.push_back(carry+48);}
- //reverse(emp.begin(),emp.end());
- int l_emp=emp.length();
- for (int b=0;b<l_emp/2;b++)
- swap(emp[b],emp[l_emp-b-1]);
- cout<<"Case "<<i<<":"<<endl;
- cout<<num3<<" + "<<num4<<" = "<<emp<<endl;
- if(i==t);
- else cout<<endl;
- carry=0;emp="";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement