Reverse of a number with leading zeroes

后端 未结 10 1545
庸人自扰
庸人自扰 2021-01-14 05:17

How do we reverse a number with leading zeroes in number ? For ex: If input is 004, output should be 400.

I wrote below program but it works only when n

10条回答
  •  时光说笑
    2021-01-14 06:06

    Replace your while loop with a for loop with the same number of runs as you wish the original number has digits (including leading zeros). e.g. 004 would require the loop to be run 3 times, and not to terminate prematurely once x == 0.

提交回复
热议问题