# Determining if a number has a remainder?

• 08-31-2001
Captain Penguin
Determining if a number has a remainder?
How could I do this in C? Knowing the remainder would be cool too.

If no one can think of a way of this, how about how can I find out if a number is even or even prime?

:-/
• 08-31-2001
Stoned_Coder
in c/c++ there is a modulus operator %

this does an integer division and returns the remainder.

I think you can work the rest out!
• 08-31-2001
Unregistered
Yes, % will work, but here's a fun way:
Code:

```int divide( int toDivide, int divideBy ) {   int x=0;   x = toDivide / divideBy;   return ( toDivide == (divideBy * x) ); }```
That should do something like:
Code:

`printf("6 / 3 = 2, is there a remainder? %s.", divide( 6,3 ) ? "No" : "Yes" );`
Alternatly, you could just make that return the remainder:
Code:

```int divide( int toDivide, int divideBy ) {   int x=0;   x = toDivide / divideBy;   return (toDivide-(x*divideBy)); }```
Quzah.
• 09-01-2001
Captain Penguin
Quote:

Originally posted by Stoned_Coder
in c/c++ there is a modulus operator %

this does an integer division and returns the remainder.

I think you can work the rest out!