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
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?
:-/
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!
Yes, % will work, but here's a fun way:
That should do something like:Code:int divide( int toDivide, int divideBy )
{
int x=0;
x = toDivide / divideBy;
return ( toDivide == (divideBy * x) );
}
Alternatly, you could just make that return the remainder:Code:printf("6 / 3 = 2, is there a remainder? %s.", divide( 6,3 ) ? "No" : "Yes" );
Quzah.Code:int divide( int toDivide, int divideBy )
{
int x=0;
x = toDivide / divideBy;
return (toDivide-(x*divideBy));
}
Hey thanks I had forgotten about the modulus operator!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!
I need to refresh my C skills.. hehe