fork(2) download
  1. #include <stdio.h>
  2.  
  3. unsigned int weirdAnd(unsigned int a, unsigned int b) {
  4. unsigned int result = 0;
  5. unsigned int coef = 1;
  6. while (a && b) {
  7. result += ((a % 10) && (b % 10)) * coef;
  8. coef *= 10;
  9. a /= 10;
  10. b /= 10;
  11. }
  12. return result;
  13. }
  14.  
  15. unsigned int weirdOr(unsigned int a, unsigned int b) {
  16. unsigned int result = 0;
  17. unsigned int coef = 1;
  18. while (a || b) {
  19. result += ((a % 10) || (b % 10)) * coef;
  20. coef *= 10;
  21. a /= 10;
  22. b /= 10;
  23. }
  24. return result;
  25. }
  26.  
  27. int main(void) {
  28. // your code goes here
  29. unsigned int a = 10110;
  30. unsigned int b = 10011;
  31. printf("%u and \n%u = \n%u\n\n", a, b, weirdAnd(a, b));
  32. printf("%u or \n%u = \n%u\n\n", a, b, weirdOr(a, b));
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
10110 and 
10011 = 
10010

10110 or  
10011 = 
10111