Advertisement
a53

adunare

a53
Nov 30th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int A[10],B[10];
  4.  
  5. int main()
  6. {
  7. int a,b;
  8. cin>>a>>b;
  9. int x=a,n=0,m=0;
  10. while(x)
  11. A[n++]=x%10,x/=10;
  12. --n;
  13. x=b;
  14. while(x)
  15. B[m++]=x%10,x/=10;
  16. int T=0;
  17. --m;
  18. if(m>n) /// Daca b are mai multe cifre decat a
  19. for(int i=n;i<m;++i) /// adaugam zerouri in fata
  20. A[i]=0;
  21. else /// a are mai multe cifre decat b
  22. for(int i=n;i<m;++i)
  23. B[i]=0;
  24. for(int i=0;i<n;++i)
  25. {
  26. A[i]+=B[i]+T;
  27. T=A[i]/10;
  28. if(T)
  29. {
  30. cout<<"Gigel nu stie! El poate cumpara "<<1ULL*a+1ULL*b<<" bomboane!\n";
  31. return 0;
  32. }
  33. A[i]%=10;
  34. }
  35. if(T)
  36. cout<<"Gigel nu stie! El poate cumpara "<<1ULL*a+1ULL*b<<" bomboane!\n";
  37. else
  38. cout<<"Gigel stie!\n";
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement