# calculating remainders

This is a discussion on calculating remainders within the C Programming forums, part of the General Programming Boards category; hey guys i'm a little stuck. i've been told to design a program that reads a number from 5 to ...

1. ## calculating remainders

hey guys i'm a little stuck.

i've been told to design a program that reads a number from 5 to 55. and the program should calculate how many of each 5, 10, 20 coins will be returned.

for example, if input is 50, the program will return 2x20 and 1x10. if input is 35, the program will return 1x20 1x10 1x5

the program has to be modular in nature
how do i do this?

can someone give an example of how i can go about doing this?

thanks

2. What is it that you need help with? Calculating remainders? Operators in C and C++ - Wikipedia, the free encyclopedia Check out the "modulo" operator.

3. For example...

The amount of 50
How many "20" coins would it contain?

50 / 20 This division will give the answer of 2. That's 2x20.
50 - 2 * 20 = 10 are left.

How many "10" coins?
10 / 10 = 1. That's 1x10.

10 - 1 * 10 = 0. No more.

4. The modulo operator divides two integers and returns the remainder between them. This statement...

Code:
`int x = (7 % 2);`
...assigns x to the remainder of seven divided by two, which is one. You can only do this with integers, there's another function that does the same thing with floating-point numbers, I can't remember it off the top of my head.

5. Originally Posted by Babkockdood
there's another function that does the same thing with floating-point numbers, I can't remember it off the top of my head.
The funciton is fmod. You have to include math.h (and maybe link the math library) to use it.