Answer to Question #280260 in C++ for Aye

Question #280260

Write a program that reverses the number entered by the user. Formulate

an equation to come up with the answer. (Hint: You are going to use the modulus

operator.)

Sample Output:

Enter a number: 1234

Number in reverse: 4321


1
Expert's answer
2021-12-16T04:46:20-0500
#include <bits/stdc++.h>
using namespace std;


int main()
{
   int num,rev = 0;
   
   cout<<"Enter a Number: ";
   cin>>num;
   
   
   while (num != 0)
   {
       rev = (rev * 10) + (num % 10);
       num = num / 10;
   }
   
   cout<<"Number in Reverse: "<<rev<<endl;
   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog