fork download
  1. #include <functional>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <vector>
  5. #include <typeinfo>
  6.  
  7. #include <cstdlib>
  8.  
  9. using namespace std;
  10.  
  11. unsigned int myAdd(unsigned int a, unsigned int b)
  12. {
  13. unsigned int carry = a & b;
  14. unsigned int result = a ^ b;
  15. while(carry != 0)
  16. {
  17. unsigned int shiftedcarry = carry << 1;
  18. carry = result & shiftedcarry;
  19. result ^= shiftedcarry;
  20. }
  21. return result;
  22. }
  23.  
  24. int main()
  25. {
  26. cout << "30000 + 1337 = " << myAdd(30000,1337) << endl;
  27.  
  28. srand(time(0));
  29.  
  30. for(unsigned i(0); i < 200000; i++){
  31. unsigned temp = rand();
  32. if(i + temp != myAdd(i,temp)) cout << "nie zgadza sie dla wartosci " << i << " + " << temp << endl;
  33. }
  34. }
Success #stdin #stdout 0.01s 2928KB
stdin
Standard input is empty
stdout
30000 + 1337 = 31337