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?

:-/

Printable View

- 08-31-2001Captain PenguinDetermining 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-2001Stoned_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-2001Unregistered
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) );

}

Code:`printf("6 / 3 = 2, is there a remainder? %s.", divide( 6,3 ) ? "No" : "Yes" );`

Code:`int divide( int toDivide, int divideBy )`

{

int x=0;

x = toDivide / divideBy;

return (toDivide-(x*divideBy));

}

- 09-01-2001Captain PenguinQuote:

*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!

I need to refresh my C skills.. hehe