Raised This Month: $ Target: $400
 0% 

Last Digit from a Integer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 03-10-2010 , 20:24   Last Digit from a Integer
Reply With Quote #1

How i can get the last digit from a integer?

Some examples:

3451
789
20
1

(retard example, ftw)

Thanks in advance.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-10-2010 , 20:35   Re: Last Digit from a Integer
Reply With Quote #2

I assume it'd be something like this.
PHP Code:
new 26

new number[] = num_to_str)

new 
lastdigit str_to_numnumbersizeof number ] )
// or if you want it as a string
new lastdigit numbersizeof number 
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 03-10-2010 at 20:39.
wrecked_ is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 03-10-2010 , 20:40   Re: Last Digit from a Integer
Reply With Quote #3

Quote:
Originally Posted by wrecked_ View Post
I assume it'd be something like this.
Code:
new i = 26 new number[] = num_to_str( i ) new lastdigit = number[ sizeof number - 1 ]
Suck Method.

PHP Code:
stock get_last_num( const int )
{
    return 
int 10 * (int 10);

I think that is correct. Just Test. I don't!!!



EDIT: Exolent method rocks!!
__________________

Last edited by AntiBots; 03-10-2010 at 20:48. Reason: EDIT
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-10-2010 , 20:45   Re: Last Digit from a Integer
Reply With Quote #4

Quote:
Originally Posted by AntiBots View Post
Suck Method.

PHP Code:
stock get_last_num( const int )
{
    return 
int 10 * (int 10);

I think that is correct. Just Test. I don't!!!
What? That makes no sense.

26 - 10 * (26 / 10 )
non-PEMDAS: 41.6
PEMDAS: 0
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-10-2010 , 20:45   Re: Last Digit from a Integer
Reply With Quote #5

You guys are either retarded or didn't think.

Code:
new iNumber = 123456; new iLastDigit = iNumber % 10; // iLastDigit = 6
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Old 03-10-2010, 20:47
Bugsy
This message has been deleted by Bugsy.
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 03-10-2010 , 21:09   Re: Last Digit from a Integer
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
You guys are either retarded or didn't think.

Code:
new iNumber = 123456; new iLastDigit = iNumber % 10; // iLastDigit = 6
EPIC PWNAGE

Programming require math skills... Actually, programming is just math hiding behind identifiers and operators.
Seta00 is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-10-2010 , 21:13   Re: Last Digit from a Integer
Reply With Quote #7

What exactly does the modulo operator return? I'm aware that it has something to do with the remainder, but that operation makes no sense at all to me. I would've thought it'd return 0, since the remainder of 123456 / 10 is 0.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-10-2010 , 21:22   Re: Last Digit from a Integer
Reply With Quote #8

Quote:
Originally Posted by wrecked_ View Post
What exactly does the modulo operator return? I'm aware that it has something to do with the remainder, but that operation makes no sense at all to me. I would've thought it'd return 0, since the remainder of 123456 / 10 is 0.
You fail at math if you think that. % returns the remainder of the division problem. 6 / 10 leaves you with a remainder of 6...
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-10-2010 , 21:26   Re: Last Digit from a Integer
Reply With Quote #9

Quote:
Originally Posted by YamiKaitou View Post
You fail at math if you think that. % returns the remainder of the division problem. 6 / 10 leaves you with a remainder of 6...
Oh, come to think of it, that was quite a dumb statement.

My bad.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 03-10-2010 , 21:34   Re: Last Digit from a Integer
Reply With Quote #10

% work like this:

I want to do: 20 % 8;

PHP Code:
Well:
0    1    2    3    4    5    6    7: ( 0 to X % (this-1) )

0    1    2    3    4    5    6    7
8    9   10   11   12   13   14   15
16  17   18   19   20 
So 20 % 8: 4

Algo you can think:

20 / 8 = 2
20 % 8 = 4.

4 / 8 = 0.5

So: 8 * 2 + 4 = 20;

Just a math lesson.
__________________

Last edited by AntiBots; 03-10-2010 at 21:39. Reason: add php
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode