• 0

[C] Quick math question for a n00b


Question

Right say I've got a number, x. (x is an integer)

I need an equation to find out how many 5's go in to x,

then how many 2's go in to the remainder,

then how many 1's go in to the remainder of that,

and then how many 0.5's go in to that

Really simple I'm guessing and it's driving me mad, so I thought I'd just ask and get it over with?

Cheers.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Uhh...Any int divided by 1 has a remainder of zero. x is an integer so the last case with 0.5 doesn't really matter?

All you have to do is take the floor of x/5. Then do x%5 to find the remainder. For the next case x is now the remainder and you do the same thing again. Take the floor of x/2. Then x%2 to find the remainder.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.