15,034,692 members
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
Posted
Updated 7-Mar-18 23:46pm

## Solution 1

% - mod
/ - div

C#
```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.

## Solution 2

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