Write a C Program to reverse a number entered by user

By | October 10, 2016

C Program  to reverse a number entered by user


Write a C program to enter any number from user and find the reverse of given number using for loop. How to find reverse of any number in C programming using loops. Program to find reverse of a given number.

C Program to reverse a number :- This program reverse the number entered by the user and then prints the reversed number on the screen.

Example:

Input number: 1234
Output reverse: 4321

Logic to find reverse :

The process of reversing involves four basic steps:

  1. Multiply the rev variable by 10.

  2. Find the last digit of the given number.

  3. Add the last digit just found to rev.

  4. Divide the original number by 10 to eliminate the last digit, which is not needed anymore.

Repeat the above four steps till the original number becomes 0 and finally we will be left with the reversed number in rev variable.

Here is source code of the C program to reverse a number . The C program is successfully compiled and run(Codeblocks) on a Windows system. The program output is also shown below.

 


SOURCE CODE : :


 


OUTPUT : :


Leave a Reply