Computer Science, asked by Shivank1852, 1 year ago

Write an algorithm to find reverse of an integer

Answers

Answered by shantanurauthan
0

Algorithm:

Here input number is: num

(1) Initialize rev_num = 0

(2) Loop while num > 0

(a) Multiply rev_num by 10 and add remainder of num

divide by 10 to rev_num

rev_num = rev_num*10 + num%10;

(b) Divide num by 10

(3) Return rev_num

I was first writing the program but then i saw algorithm written at top in your question.

Once you know the program the algorithm can be made easily and vice-versa.

Hope this helps :)

Similar questions