Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2008-02-26 04:52:00

spank
Member
Registered: 2008-02-26
Posts: 1

Function problem

I have to write a function f(n) that has the result the lowest number higher or equal to n that is dividable by 4.
For ex:

f(24) = 24, f(25)=28 ...

The only solution that I can think of is:

f(n) = [n/4+1]*4.

But it doesnt work for n numbers that are dividable by 4.

Thank you and sorry if I've made some mistake, I'm new here!

Offline

#2 2008-02-26 05:47:49

TheDude
Member
Registered: 2007-10-23
Posts: 361

Re: Function problem

You're very close, just leave out the 1 and use the ceiling function (I can't tell from your post if you were using the ceiling or floor function):

Last edited by TheDude (2008-02-26 05:48:48)


Wrap it in bacon

Offline

Board footer

Powered by FluxBB