Mirror value of a number

Solved
Gyl-Mael Posted messages 1 Status Member -  
 Gyl-mael -
Hello,
I would like to write a program in C that reads a number and displays its mirror value; for example, the mirror value of the number 456 is 654.

Configuration: Windows XP / Firefox 21.0

4 answers

  1. fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
     
    Thinking about it, there's an even simpler way. And in my opinion, it's the expected way if it's for an assignment.

    number : integer (chosen by the user)
    remainder : integer (between 0 and 9, unit)
    result : the mirrored number

    Request(number)

    result <- 0
    While number > 0 Do
    remainder <- number modulo 10
    number <- number / 10
    result <- result * 10 + remainder
    EndWhile

    Display(result)
    I'll let you write the code ;-).

    PS: the algorithm works for positive numbers, it's up to you to see if you need to adapt it for negative numbers.
    Best regards,

    Google is your friend.
    11
    1. Sugel Posted messages 4293 Registration date   Status Member Last intervention   728
       
      Here, that's true!

      There are plenty of ways to do it...
      0