I'll already add here that the output for 225 will be 230 from this algorithm and not 300 as the OP has asked. Reason: My implementation is that way. There is not really any right answer to this question. More than coding this is a designing question.
Idea: Use a map of int to int such that if, key is the number, then value is what should be added to it to get the appropriate number. Extract the digits of the input from the right end and continue to improve the number from its right end moving towards its left one digit at a time.
The map (let's call it additive) would have {key, value} pairs like:
{1, 9}, {2, 8}, ... , {9, 1}, {20, 0}, ..., {90, 10}, ...
Note that you would not need to add every integer to it. Adding only some integers would be enough, if you use the map properly.
Here is the code/pseudocode for you to get proper value from the input number:
int GetProperNumber(int input) {
//Init a variable to keep track of the sign
int multiplier = 1;
//For negative numbers, taking some precaution...
if (input < 0) {
input *= -1;
multiplier *= -1;
}
//For cases where the input number is only 1 or 2 digits, some quick checks...
int numberOfDigits = GetNumberOfDigitsInInput(input);
if (numberOfDigits == 1) return (input + additive[input]) * multiplier;
if (numberOfDigits == 2) return (input + additive[input - input/10]) * multiplier;
//Now, coming to the core of the method
int divisor = 10; //We'll use it to get the left part from the input
while (true) {
//First, get right part of the number
int inputWithDigitsRemoved = input / divisor;
//If the leftover part is too small, i.e. we have reached the last digit,
//then break as we have now rounded the number off pretty well.
if (inputWithDigitsRemoved <= 9) break;
int inputWithDigitsMasked = inputWithDigitsRemoved * divisor;
int right = input - inputWithDigitsMasked;
//Since the number is still not rounded to the right magnitude,
//the result should be further improved.
if (additive.Contains(right)) input += additive[right];
divisor *= 10;
}
return input * multiplier;
}
Some sample result would be:
Input = 5, Output = 10
Input = 99, Output = 100
Input = 2541, Output = 2600