41.3k views
4 votes
Write a program which get interger numbers and make it in reverse order.

User Mr Jones
by
5.4k points

1 Answer

4 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

int num,a,digit;

a=0;

cout<<"Enter the number"<<endl;

cin>>num;

while(num>0)

{

digit=num%10;

a=a*10+digit;

num/=10;

}

cout<<"Reversed number is "<<a<<endl;

return 0;

}

Step-by-step explanation:

Taking input of an integer num.

Initializing an integer a with value 0.

looping over n while it is greater than zero.

By using modulus operator(%) we will get the last digit.

Storing the digit in a.

Dividing num by 10;

After the loop is over we will get the answer in a.

User Markvandencorput
by
5.6k points