Question

how to solve this on c++?

Write a program that reads a five digits integer, then swaps the unit position digit with the ten thousandth position digit, also swap the tenth position digit with the thousandth position digit. Print the new number For example if the number is 37846 then the new number is 64873. Sample input / output: nter a five digits integer The new form of the number 37846 is 64873

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
int main(){
   int number,rem,reverseNumber=0,tempNumber;
   cout << "Enter any number : ";
   cin >> number;
   //tempNumber is used to stored the number
   tempNumber = number;
   //runs until number > 0
   while(number>0){
       rem = number%10;
       number=number/10;
       reverseNumber = reverseNumber*10+rem;
   }
   cout << "The new form of the " << tempNumber << " is : " << reverseNumber;
   return 0;
}

output:

Terminal Enter any number 36589 The new form of the 36589 is: 98563 (program exited with code: 0) Press return to continue

Add a comment
Know the answer?
Add Answer to:
how to solve this on c++? Write a program that reads a five digits integer, then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT