Reverse printing a number using a loop – CSKC
Sign In

Search

Code Learning #CPP#2115    siteicon   siteicon  

Reverse printing a number using a loop

Printing a number in reverse order of digit by using digit extraction technique in a loop

Learning Objectives

  • A loop technique to manipulate printing inside a loop so that display of desired reversed number can be achieved without actually storing the number.

Source Code

TC++ #2115

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

Notes

  • One can write the same program in many other ways where reversed number is stored in another variable and then printed. This is a better way when you need to use the reversed number in some other calculation after the loop.
  • Before starting the loop in this case we have not copied the input number to another number as we have not printed the original number after the loop. Although it is always a good idea to do so.

Common Errors

  • Take care of not writing any endl or newline character while printing the digit as in this case you do not want any gap to be printed between the digits while printing the number in the reversed order.


Suggested Filename(s): rev-num.cpp



Share

Created: 2-Jan-2018 22:24 | Updated: 15-Sep-2018 12:44|