5
how do I use the MOD function in C C++?
(N MOD 2) = 0
I have to use this line of my code.
5
how do I use the MOD function in C C++?
(N MOD 2) = 0
I have to use this line of my code.
12
The MOD operator is the %
.
int n = 40;
if (n % 2 == 0) {
cout << num << " é par";
}
Additionally see std::modulus
Browser other questions tagged c c++
You are not signed in. Login or sign up in order to post.
[Error] invalid operands to Binary % (have 'float' and 'int') now giving this error could explain me why?
– matheus ferreira
Why the rest of the division operator is for operations with integer numbers and you are trying to do this with a
float
. In the case of floating numbers this operator makes no sense, the division of afloat
ordouble
will leave no remains (although the result is not accurate due to how these types work, afloat
divided by afloat
or aint
there’s always rest0
).– Anthony Accioly
Behold Why does modulus Division (
%
) only work with integers? (SOE).– Anthony Accioly
And when the operand is less than the operator, ex: 1 % 2 != 0?
– user44005
@Robson, think about
mod
as the rest of a division. If you split a numbern
for a value greater thann
the entire division will be0
and P rest (module) will ben
.– Anthony Accioly