1
int mult2_recurse(int a, int b) {
}

Hello, I'm trying to fill in this function, which is passed 2 variables - called with different variables a couple times. I have to add the two variables without using any of *, /, +, =, *=, /=, +=, -= operators. I can only use ++ and/or -- operators. Can someone help me? I've tried numerous ways and can't seem to wrap the logic around my head.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Chris22
  • 21
  • 2

1 Answers1

5

For unsigned solution is:

unsigned add2_recurse(unsigned a, unsigned b){
    return (0 == b) ? a : add2_recurse(++a, --b);
}
Maxim Kholyavkin
  • 4,463
  • 2
  • 37
  • 82