A challenge for all newbies
Find a six digit number that gives its digits reversed when multiplied by an integer between 2 and 9 inclusive. For example, if the original number was 654321 and the chosen integer was 8, then 654321 x 8 should equal 123456 if it was the magic number (which of course it doesnt). There are two (2) solutions.
Lets see who is the first to find out the exact numbers .... you can make a small program or you can do it MANUALLY :mrgreen: :evil:
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
wow ALT F4 ... you did it .. what algo did you use for it
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
nice work ... I first reversed the number by modulus .. and then started off from 499999 .... in this way the processor had to do half the work :). Your idea of reversing the number is also good.
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
I'll try to find some more of them.
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
>Q.E.D.
Yes, but is it correct? The question clearly states "variables" yet your cute little trick will only work on integral types. What about pointers? If a and b are pointers and they point to the same object, you certainly won't get a swap out of this.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Here it is in Java notation. I don't know C.
int a;
int b;
a = a+b;
b = a-b;
a = a-b;
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20