+ 4

Math question for Ruby

What is the output of 5-2*3+3? I think, it is 4, but the answer is 2, I don't understand

6th Jan 2017, 9:54 PM
Anderson Farid Palacio Agudelo
Anderson Farid Palacio Agudelo - avatar
15 ответов
+ 8
5-2*3+3 first the 2*3 will execute which will be 6 now we've got: 5-6+3 5-6 is -1 -1+3 is 2 easy ^^
6th Jan 2017, 10:20 PM
Kamil
Kamil - avatar
+ 8
That's because of the highest priority of the multiplication operator... If you're not sure, use parenthesis to get the expected result ^^
7th Jan 2017, 2:56 AM
visph
visph - avatar
+ 4
2 * 3 = 6 5 - 6 = -1 -1 + 3 = 2
8th Jan 2017, 10:16 AM
Carmelo
+ 4
@Greg Oboroceanu: Addition and substraction are done from left to right priority ^^
2nd Feb 2017, 11:24 AM
visph
visph - avatar
+ 3
certainly 2 is the answer
15th Jan 2017, 2:57 AM
CHUN
+ 2
ohhh yeah thank you!!! :)
6th Jan 2017, 11:08 PM
Anderson Farid Palacio Agudelo
Anderson Farid Palacio Agudelo - avatar
+ 2
The answer is 2
20th Jan 2017, 11:26 AM
Renice Owino
Renice Owino - avatar
+ 2
5-2*3+3 =5-(2*3)+3 (multiply is priorité to make) =5-6+3 (they group the positive numbers =5+3-6 and the negaitve number) =8-6 (then, thay execute them) =2. ( finally, answers is 2)
21st Jan 2017, 1:43 PM
CHUN
+ 1
* and / are operated first
10th Jan 2017, 9:53 AM
Alvaro Wenceslao Ponce
Alvaro Wenceslao Ponce - avatar
+ 1
=5-2*3+3 =5-6+3 {multiply 2 and 3} =-1+3 =2 So, 2 is the answer.
11th Jan 2017, 4:54 AM
Balwinder Kumar
Balwinder Kumar - avatar
+ 1
the Answer will be 2 positive
14th Jan 2017, 6:51 AM
Tiptop
+ 1
yeah it's 2 as firstly -2*3= -6 and then 5+3=8 so basically -6+8=2
20th Jan 2017, 3:12 PM
harshcr7
+ 1
please help me clarify why is the addition operator not evaluated first? =5-(2*3)+3 =5-(6+3) =5-9 =-4??
2nd Feb 2017, 10:48 AM
Greg Oboroceanu
Greg Oboroceanu - avatar
+ 1
BODMAS should be applied I think so...
3rd Feb 2017, 3:02 PM
Nayem Ahamed
Nayem Ahamed - avatar
+ 1
considering the given calculation, it follows the arithmetic operation precedence. first you need to check for multiplication or division or the other way(whichever comes first from left to right), then proceed with addition or subtraction or the other way(whichever comes first from left to right).
11th Feb 2017, 10:21 PM
leojr4fox
leojr4fox - avatar