567894 output will be 56894

i have a problem, if the user will enter 567894 and the output must be:
56894 and the number remove is 7
what will be the possible code on this one?
Last edited on
There are several approaches to this problem. Without more details on what you can use for the assignment we can't be more useful. The easiest way would probably be to read into a string and just output everything but the digit to be removed from it. You could also do some nifty math tricks something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int number = 567894;
int numberToRemove = 7;
int result = 0;
int power = 1;
while(number)
{
    int digit = number % 10; //rightmost digit
    if(digit != number)
    {
        result += digit * power;
        power *= 10;
    }
    number /= 10;
}


Topic archived. No new replies allowed.