If x=4 then what will be the output of X/2, x//2 and x%2. Give the reason.
Answers
Answered by
3
ANSWERS.
- x/2 = 2.0
- x//2 = 2
- x%2 = 0
EXPLANATION.
Here, the value of x is 4.
'/' operator is used to perform division and returns floating point result.
So,
x = 4
print(x/2)
> 2.0
'//' operator is used to perform floor division. It is used to calculate the quotient after division.
So,
x = 4
print(x//2)
> 2
'%' operator is used to calculate the remainder obtained after division.
So,
x = 4
print(x%2)
> 0 As 4 divided by 2 leaves 0 as remainder.
Answered by
3
Your answer is as follows::
Question::
If x = 4, then what will be the output of x / 2, x // 2 and x % 2
Answer::
x / 2
==> 4 / 2
==>2.0
◆ It gives the answer on dividing.
x // 2
==> 4 // 2
==> 2
◆ It outputs the quotient.
x % 2
==> 4 % 2
==> 0
◆ It gives remainder as output. "%" is called modulo sign
● "//" in java is used for comment and therefore it can't be used quotient in java.
● The given question is in python. "%" and "/" can be used for same in java.
Similar questions