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.

7823 Mod 103
782 Mod 10
78 Mod 10
7 Mod 10

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


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad