Jump to content

changing the number order in C++

alphabeta

So let's say That I have a number X and X = 123 And I want to change it's order to 321 , How Might I do it .. is it has a function ?? or I'll have to do it my self??

 

** C++ **

Link to comment
Share on other sites

Link to post
Share on other sites

Another option that doesn't use strings is to use the modulus operator (%)

 

Hint:

number % 10 // will return the last digit. Ex) 123 % 10 = 3number / 10 // will return the number minus the last digit. Ex 123 / 10 = 12

With that information, you can build the number in reverse just using integers and some math.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×