Advertisement
Guest User

c++

a guest
Jan 30th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. string dod(string a,string b)
  6. {int p=0,w=0;
  7. string wynik;
  8. while(a.size()!=b.size())if(a.size()<b.size())a='0'+a;
  9. else b='0'+b;
  10. for(int i=a.size()-1;i>=0;i--)
  11. {
  12. w=int(a[i]-'0')+int(b[i]-'0')+p;
  13. wynik=char(w%10+'0')+wynik;
  14. p=w/10;
  15. }
  16. if(p>0)wynik='1'+wynik;
  17. return wynik;
  18. }
  19. int main()
  20.  
  21. {
  22.  
  23.  
  24. string a,b;
  25. cin >> a >> b;
  26.  
  27. cout<<dod(a,b);
  28.  
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement