Reversing digits of an integer

Reversing digits of an integer

Problem Definition: Reversing the digit of an integer.

Problem Analysis: Given a integer number, abcd (say 1234where a=I, b=2andso on), the algorithm should convert the number to dcba.

Solving by Example: Consider an integer number 7823.

The reverse of an integer number is obtained by successively dividing the integer by 10 and accumulating the remainders till the quotient becomes less than 10.

The remainder of a division operation can be found out by the mod function.

Accumulated Quotient
7823 Mod 103 782
782 Mod 10 3278
78 Mod 10 328 7
7 Mod 10 3287 0

Algorithm Definition

Step 1: Start

Step 2: read the integer n to be reversed.

Step 3: Initialize rev to zero.

Step 4: Write 'n' is greater than 0, does the following step:

(a) Divide the integer n by 10

(b) Store the quotient to n.

(c) Multiply 10 to the already existing value of rev.

(d) Add the remainder to the value of rev.

Step 5: Print the value of rev.

Step 6: Stop

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz