Mirror value of a number
Solved
Gyl-Mael
Posted messages
1
Status
Membre
-
Gyl-mael -
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
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 réponses
Thinking about it, there's an even simpler way. And in my opinion, it's the expected way if it's for an assignment.
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.
I'll let you write the code ;-).
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)
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.
There are plenty of ways to do it...