0
Print(2*5-2%1) what to do first? Tell me whole process.
7 Antworten
+ 5
first we have will see which operators have high precedence
In the question, (*,%) has high precedence than (-)
(*,%) has equal to precedence so we will use it associativity rule i.e. left to right so the operator from (*,%) will be solved first that is one the left side
We will solve it like this-
(2*5-2%1)
(10-2%1) * is on the left side so it got first solved before %
(10-0) % has more precedence than -
10 10 is the final answer
Hope you got understand........
+ 7
It is actually following the rule of BODMAS...
Brackets
Orders
Division
Multiplication
Addition
Subtraction
Here Print(2*5-2%1) has no bracket so passes to division method i.e. 2%1 = 0 then multiplication 2*5 = 10 then at last substraction of 10-0 which is 10 ....so it will print 10...
+ 7
Ben sidhom Akram Bro firstly division is done then multiplication.....
+ 2
1. 2*5=10
2. 2%1=0
3. 10-0=10
+ 2
* and % have the same precedence and their precedence is higher than that of -
Therefore this is evaluated as follows, (2*5)-(2%1) which gives 10.
+ 2
Thanx to all.
- 1
Firstly , do the multiplication of 2*5=>10
Secondly , do the modulo of 2%1=>0
Finally do the subtraction =>10-0=10