-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Wednesday, 8 April 2015

calculating the reverse of a number

Reverse of a number

Hello and Asalam o Alikum.I hope you all are fine by the grace of Allah Almighty.
Today I am here with a new program that will take a number as input from the user and then  calculate its reverse.

Below is the source code of this program.

Source code

khgamujtaba,C++,finding reverse of a number

Output

khgamujtaba,C++,finding reverse of a number

Explanation:

                 Suppose I take a number "123" as input from the user.So, according to given condition,
1. x=0*10+(123%10)
  =0+3
  =3
n=123/10=12
2. x=3*10+(12%10)
     =30+2=32
   n=12/10=1
3. x=32*10+(1%10)
      =320+1
      =321
   n=1/10
     =0
    So,it will be terminated as the value of x now becomes 0 and output will be shown as "321" which is reverse of "123".
   

No comments:

Post a Comment