# Thread: Determining if a number has a remainder?

1. ## 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?

:-/ 2. 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! 3. 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. 4. 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! Popular pages Recent additions 