+ 3
Can anyone tell me working of this code.
This is code #include <iostream> using namespace std; int main() { int x=5; x=x*8%x; cout<<x; return 0; } it's output is 0. even when I changed 8 with any other number it is give output also 0.
7 Respostas
+ 8
Hmm...
x = 5
x = 5*8 = 40 % 5 = 0
print x = 0
x = 8
x = 8*8 = 64 % 8 = 0
So far there is no error in the code and it gives the right output
+ 6
@Rajesh Kumar(Rj) It would still output 0 (Refer to mine or M Rey's code)
+ 5
a*x%x will give 0 for all integers a, as a*x always is divisible by x.
+ 3
yeah, because 5*8=40
and 40%5=0;
u can use for 8 any other number and it will be always returns 0.
+ 3
if I change 8 with 5 .
+ 1
test it, but i think it will returns 0
+ 1
u should change ur x