+ 1
Who can explain this question please?
What is is the output of this code? int x=0; x%=6; cout<<x; Answer=0
10 Respuestas
+ 4
x %= 6 is the same as: x = x % 6
Since modulo (%) looks at the remainder of a division,
e.g. 4%2 = 0, because no remainder
e.g. 5%2 = 1, because there is a remainder of 1
Applying this rule, we get this expression:
0%6 , which is 0/6.
0/6 is 0, therefore 0%6 = 0, because there are no remainders
+ 3
Dinomath YT there is a little mistake in your answer that will be confusing to a beginner. 5%10 = 5 (not 0) because 5/10 = 0 with remainder 5. [Check: 0*10 + R5 = 5]
+ 2
Brian sry, my mistake I typed wrong i was saying ( 10%5) and
By dividing 10 to 5 we will got 2 and remainder 0.
+ 1
modulo (%) looks at the remainder of a division,
e.g. 5%2 = 1, because there is a remainder of 1
x %= 6 is the same as: x = x % 6
Applying this rule, we get this expression:
Now, x = 0%6
The remainder of this equation is 0, therefore 0%6 = 0
0
What don't you understand?
The % (modulo) or cout<<x?
0
How( 0%=6;) ?
0
0/6=0 is correct
But why 0%6=0?
0
% modulo operator is doing a normal division to see if there is a remainder or not.
Since we are doing 0/6 - we get 0, therefore there are no remainders ,
0
The fundamental of (%)<--module:
Module help to find reminders of any two numbers, e.g(5%10=by dividing 5 & 10,ans will be 2 and remainder will be 0)
Just like in this case:
(x%6) means 6 module with a variable and at last u puted the value of x=0, so that means ,0%6,if we divide it we will get 0 and remainder zero too , because dividing any number with zero provide remainder and quitient 0.
I hope u understood ! :)
0
in c and cpp modules to smaller value the answer is always smaller value i.e divide smaller by bigger value answer is always smaller one