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?
:-/
This is a discussion on Determining if a number has a remainder? within the C Programming forums, part of the General Programming Boards category; How could I do this in C? Knowing the remainder would be cool too. If no one can think of ...
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!
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
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!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