Monday, 10 December 2018

Algorithm for reversing given number


Reversing  given number

Algorithm for reversing given number:
Step1  :   Start
Step2  :   Declare three variables n, rev and r
Step3  :   Read number to be reversed from keyboard ( n )
Step4  :   Assign value 0 to rev
Step5  :   Assign n modulus 10 value into r
Step6  :   Multiply rev value with 10 and add r to it. Store this value in rev.
Step7  :   Divide the number n by 10
Step8  :   Repeat steps 5  to 7 until n is not equal to 0
Step9  :   Print the reversed number ( rev )
Step10:   Stop



No comments:

Post a Comment