Algorithm
- Take number
n
. - Initial
rev = 0
- Find Reminder =
n % 10
rev = rev * 10 + remainder
n = n/10
- Continue step
3-5
until number is not equal zero.
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main() {
int n, rev = 0, remainder;
printf("Enter a number: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", rev);
return 0;
}.
Copy The Code &
Try With Live Editor
Input
Enter a number: 123
Output
Reversed number = 321
Demonstration
C Programming Example to Reverse a Number.
Get more related example of reverse number is palindrome number - https://devsenv.com/codes/palindrome-number-solution-in-c-programming-coding-example-many-examples-in-c-for-palindrome-check
Practice Online of C programming - https://devsenv.com/page/run-c-programming