Computer Science Canada Manipulate Integers |
Author: | Blade [ Sun Mar 30, 2003 10:52 am ] |
Post subject: | Manipulate Integers |
how can you get the digits from integers... what i want to do is take a number... get the last digit, delete it then subtract it from the whole number... |
Author: | azndragon [ Sun Mar 30, 2003 11:29 am ] | ||
Post subject: | |||
This is used with the () after calling the variable. You do this:
Basically, this program converts the input into a string, takes the last letter, converts it back to an integer, and subtracts it from the original number. |
Author: | Blade [ Sun Mar 30, 2003 11:39 am ] |
Post subject: | |
yeah, thats pretty much what i did... i thought there was a way i could do it without converting it to a string... but i guess not eh.. |
Author: | Tony [ Sun Mar 30, 2003 2:00 pm ] | ||
Post subject: | |||
well if its just the last number, you can divide the whole number by 10 then subtract same number rounded down then multiply back by 10... since the line above doesnt make sence even to myself, I'll just show you the code:
|
Author: | azndragon [ Sun Mar 30, 2003 2:13 pm ] |
Post subject: | |
Yeah, Tony's suggestion works well. I just don't know the shortcuts in programming, but then again, I've only been programming for about 4 months now, maybe experience allows you to learn the good shortcuts. |
Author: | Tony [ Sun Mar 30, 2003 3:37 pm ] |
Post subject: | |
well its more of being able to look at problem from different perspectives... while in azndragon's solution he used turings ablitity to turn integer into a string (which he is able to manipulate well)... I used mathimatical approach. its all about "thinking outside the box" and trying out new ways of doing things. I suppose that comes with experimenting or having a creative mind to begin with. (Note: you'll not get it unless you try it... such as experience is nothing without experimenting) |
Author: | azndragon [ Sun Mar 30, 2003 4:03 pm ] |
Post subject: | |
tony wrote: well its more of being able to look at problem from different perspectives...
while in azndragon's solution he used turings ablitity to turn integer into a string (which he is able to manipulate well)... I used mathimatical approach. its all about "thinking outside the box" and trying out new ways of doing things. I suppose that comes with experimenting or having a creative mind to begin with. (Note: you'll not get it unless you try it... such as experience is nothing without experimenting) It's kinda ironic that I didn't take the mathematical approach, because if you know me, I'm all math (which is pretty much all programmers should be ) |