Click here to Skip to main content
15,034,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone! I am a noob in C++/CLI, I d like to ask a small question:

I need to get the MOD and the DIV of two integer variables A and B,

How can I do A=A(MOD)B and A=A(DIV)B in the right syntax and... should I add an special header to my code in order to use these!??? THANKS
Updated 7-Mar-18 23:46pm

% - mod
/ - div

int i1 = 5 % 2; // i1 == 1
int i2 = 5 / 2; // i2 == 2
Espen Harlinn 12-Oct-11 10:07am
Right :)
Member 13715279 8-Mar-18 7:58am
How you do DIV if i2 is type real instead of int?
jeron1 8-Mar-18 10:46am
You probably shouldn't resurrect a 7 year old thread, but instead start a new one, but take a look Basic Math coding - C++ Forum[^] for some rules using division.
While Simon is entirely right there is also
ldiv_t ldiv ( long int numerator, long int denominator );

Which returns the integral quotient and remainder of the division of numerator by denominator as a structure of type ldiv_t, this structure has two members quot and rem. If you need both results calling ldiv is more efficient.

Best regards
Espen Harlinn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900