0
Who can explain me this? C++
I wrote this code to find the pair numbers into de 1 to 25. I wrote well the code but I want to know the symbol "%" how works into the "If". https://code.sololearn.com/cjcG7Sp3YyM6/?ref=app
12 Respuestas
+ 2
sp you made for loop from 1 to 25(incl)
all even numbers modulus by 2 equals 0(dividet by 2 an got reminder 0) and we got
2,4,6.....24
+ 3
'%' gives remainder after division ,So here when n%2 means it gives remainder after dividing with 2 .As it is Number 2 it just divides numbers and yields 0 or 1 as reminder .When it's even number it gives remainder 0 therefore, 0 is equal to 0 it becomes true and evaluated to be true and prints Number.
+ 2
Vivek all numbers ar divisible by 2 3/2 is 1.5 so it is not correct explanation. Division by two WITHOUT REMINDER gives us even numbers.
+ 2
divisble in the sense means it divides the whole no
+ 1
ok my friend % is division by modulus.
you know that when you divide even numner to 2 you always got number without the reminder.
+ 1
when it goes to if section It checks the condition that number%2==0 or not means
suppose your number is 4
then it checks 4%2==0 or not
so 4%2=0
% just used to get remainder.
4/2 when you divide this then u get 0.
so in this way the number you get on the output screen all are divisible by 2 or you can say all are even number.
+ 1
like 4/2 remaimder 0 but 3/2 remainder 1.5
+ 1
You are wrong. 2/4=0.5 3/2=1.5 in case of int there are 0 and 1 but in case of float or double there are 0.5 and 1.5 corresponding.
so Division by 2 without remainder it is not the same as division by 2.
+ 1
sryy 4/2
+ 1
another example 25%24 gives u 1
in int. 25/24 remqinder 1
+ 1
Only in case of int!!!!. But division is /, modulus or division by modulus is %.
So never use assign int after division except if it really necessary.
0
george
VIVEK NIRMALKAR
Thank you so much!