English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm trying to create a mathematical formula to extract the rightmost (one's) digit of an integer.

So that f(245) =5, f(0) = 0, f(9999999)=9

Note, I'm looking for a formula, not an algorithm.

I tried messing around with base changes, and logarithms, but I'm probably just missing something obvious.

2007-02-23 17:45:04 · 6 answers · asked by Vegan 7 in Science & Mathematics Mathematics

6 answers

assuming you already have a formula for INT (integer - i.e. everything up to the decimal point) it would be :
x-10(INT(x/10))

2007-02-23 17:51:11 · answer #1 · answered by hot.turkey 5 · 0 0

6) That would be the 4, 13, 15 triangle with area 24. Second place tie 3, 25, 26 and 9, 10, 17 both with area 36.

2016-05-24 04:52:53 · answer #2 · answered by Anonymous · 0 0

Are you allowed to use the floor function?

Floor (99.8) = 99
floor (1.4) = 1
Floor (2.8) = 2

The formula to obtain the one's digit of an integer is

f(n) = n - 10*floor(n/10)

2007-02-23 17:55:36 · answer #3 · answered by Puggy 7 · 0 0

f(n) = n - 10 x int(n/10) with
n is an integer and
int(n/10) takes the whole ( = integer) part of n/10, so the fraction part has been left.

Th

2007-02-23 19:22:12 · answer #4 · answered by Thermo 6 · 0 0

if (5) =245, f(0) 99999= 45

2007-02-23 17:49:11 · answer #5 · answered by Victor Nunez 1 · 0 0

f(x)=x mod 10

for x positive and

f(x)=10-(x mod 10)

for x negative.

Finding a formula that isn't an algorithm will be quite tricky because a formula is an algorithm.

2007-02-23 18:46:52 · answer #6 · answered by Anonymous · 0 1

fedest.com, questions and answers