get the last # from a 2 digit sum
-
Hey, Is there a way that you can take the last number (one's digit) from a sum of 2 numbers added together? For example if I have numbers like 4, 8 that = 12. I only want to take the 2 though. Is this possible? Thanks Matt Matt Millican http://www.internetmill.com
-
Hey, Is there a way that you can take the last number (one's digit) from a sum of 2 numbers added together? For example if I have numbers like 4, 8 that = 12. I only want to take the 2 though. Is this possible? Thanks Matt Matt Millican http://www.internetmill.com
#include < math.h>
int a = 8;
int b = 4;
int lastDigit = (a + b) - (int)pow(10, (int)log10(a + b)));-c
When history comes, it always takes you by surprise.
-
Hey, Is there a way that you can take the last number (one's digit) from a sum of 2 numbers added together? For example if I have numbers like 4, 8 that = 12. I only want to take the 2 though. Is this possible? Thanks Matt Matt Millican http://www.internetmill.com
-
#include < math.h>
int a = 8;
int b = 4;
int lastDigit = (a + b) - (int)pow(10, (int)log10(a + b)));-c
When history comes, it always takes you by surprise.
-
Chris Losinger wrote: int lastDigit = (a + b) - (int)pow(10, (int)log10(a + b))); :omg: I guess I didn't think of it that way ;P - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
:) i like a solution that's more complicated than the problem it solves. -c
When history comes, it always takes you by surprise.
-
Hey, Is there a way that you can take the last number (one's digit) from a sum of 2 numbers added together? For example if I have numbers like 4, 8 that = 12. I only want to take the 2 though. Is this possible? Thanks Matt Matt Millican http://www.internetmill.com
Surely you can use the MOD operator?
int b = 4;
int c = 8;
int a = ((b + c) % 10);Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
-
Hey, Is there a way that you can take the last number (one's digit) from a sum of 2 numbers added together? For example if I have numbers like 4, 8 that = 12. I only want to take the 2 though. Is this possible? Thanks Matt Matt Millican http://www.internetmill.com
Try:
int a = 4;
int b = 8;
int c = (a + b) % 10;I think it is the fastest.
-
:) i like a solution that's more complicated than the problem it solves. -c
When history comes, it always takes you by surprise.
-
Try:
int a = 4;
int b = 8;
int c = (a + b) % 10;I think it is the fastest.
-
I'm keeping my mouth shut. :laugh: Tim Smith I'm going to patent thought. I have yet to see any prior art.
come on, spit it out. i'd hate for you to have to hold back. -c
Image tools: ThumbNailer, Bobber, TIFFAssembler
-
come on, spit it out. i'd hate for you to have to hold back. -c
Image tools: ThumbNailer, Bobber, TIFFAssembler
Nah, was just going to be my same rant about some of the overly complex solutions to simple problems. It is the same rant I have always had. I wanted to spare people the misery. :laugh: Tim Smith I'm going to patent thought. I have yet to see any prior art.