Explore
ProGrad Programs
About Us

Edit
Reply




Edit

Program to Reverse a Number in C, C++, Java and Python | FACE Prep

Published on 10 Mar 2020

Program to reverse a number is discussed here. We can reverse a number using loop and arithmetic operators in both iterative and recursive approaches.


For example,

Input: 13579

Output: 97531


Algorithm to reverse a number


  • Input the number from the user.
  • Perform rem = number % 10 and print rem.
  • Perform number = number / 10.
  • Repeat steps 2 and 3 until the number cannot be divided any further.


Iterative program to reverse a number


C
C++
Java
Python 3

Output
Enter a number : 12345
Reversed Number : 54321


Time complexity: O(log(n))


Recursive program to reverse a number


C
C++
Java
Python 3

Output
Input: 12345
Output: 54321


Time complexity: O(log(n))


Recommended Programs







If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in