+ 2

REVERSE ME

LIMITATIONS: NO ARRAY, NO BUILT IN FUNCTION. An integer that has a min. number of 4 digits and max of 10 digits. Sample input: 1234567 Sample output: 7654321 please help me with this one ASAP.

16th Oct 2016, 1:45 PM
Johannes Remotigue
Johannes Remotigue - avatar
4 ответов
+ 9
//using loops and recursion (2 methods ) ☺ //hope it helps ☺ https://code.sololearn.com/cX6szu5M3Lud/?ref=app
18th Oct 2017, 12:20 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
I'll give you a rough sketch. Seperating the last digit from the others is as easy as dividing by 10: int a = 1234; int division = a / 10; // 123 int remainder = a % 10; // 4 You'll also need a total which will store the result. It starts out as 0, and during each iteration you do: total = total * 10 + remainder; And that's it. You do that in a loop until you've consumed all the digits. Try printing out the division, remainder, and total at each step so you get a feel for what's going on.
16th Oct 2016, 1:51 PM
Schindlabua
Schindlabua - avatar
+ 2
thank you. :)
16th Oct 2016, 1:53 PM
Johannes Remotigue
Johannes Remotigue - avatar
+ 2
Thank you. it helps so much@Gauruv
18th Oct 2017, 12:24 PM
Johannes Remotigue
Johannes Remotigue - avatar