To do this you need to extract the tens digit and ones digit seperately, add them seperately, then put them back together.
Here's an example: note that it isn't going to help you prevent the carries for the hundreds. For that you'd have to adapt the algorithm to handle it specifically, or split up the numbers by digits and add them that way.
int crazyAdd(int a, int b) { int aTens = a % 10; int bTens = b % 10; int tens = aTens + bTens; int ones = (a + b) % 10; return tens + ones; }
Here's one that's more flexible
int crazyAdd(int a, int b) { int[] aDigits = extractDigits(a); // let there exist a function that int[] bDigits = extractDigits(b); // puts the digits into an array int size = aDigits.length; if(size < bDigits.length) size = bDigits.length; int digits = new int[size]; for(int i = 0; i < digits.length; i++) { int aDigit = i >= aDigits.length ? 0 : aDigits[i]; int bDigit = i >= bDigits.length ? 0 : bDigits[i]; digits[i] = (aDigit + bDigit) % 10; } int result = 0; for(int digit : digits) { result = result * 10 + digit; } return result; }