Here in this program, we will reverse a number. First, we will ask the user to Enter a number and then use an algorithm to reverse a number and print it.
Reverse Number Program in C++
#include<iostream.h>
#include< conio.h>
#include<stdio.h>
void main()
{
clrscr();
int num, r=0, dig;
cout<<"Enter a number: ";
cin>>num;
while(num!=0){
dig = num%10;
r = (r*10)+dig ;
num = num/10;
}
cout<<"The reverse is: "<<r;
getch();
}
Output:
Enter a number: 2453
The reverse is 3542
Reverse Number Program in Python
num= int(input("Enter a number: "))
r=0
while num!=0:
dig = num%10
r =(r*10)+dig;
num = num//10
print("The reverse is",r)
Output:
Enter a number: 44672
The reverse is 27644
People are also reading:
- WAP to find the divisors of a positive Integer
- Python Program to Shuffle a Deck of Cards
- WAP to check whether the entered number is prime or not
- Python Program to Find HCF or GCD
- WAP to Display Fibonacci Series
- Python Program to Generate a Random Number
- WAP to raise any number x to a Positive Power n
- How to Find Square Root in Python?
- WAP to calculate the sum of two numbers
- Rectangle & Pyramids Pattern in C++
Leave a Comment on this Post