+ 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

15 Answers

+ 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 ^^

+ 8

That's because of the highest priority of the multiplication operator... If you're not sure, use parenthesis to get the expected result ^^

+ 4

2 * 3 = 6
5 - 6 = -1
-1 + 3 = 2

+ 4

@Greg Oboroceanu:
Addition and substraction are done from left to right priority ^^

+ 3

certainly 2 is the answer

+ 2

ohhh yeah thank you!!! :)

+ 2

The answer is 2

+ 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)

+ 1

* and / are operated first

+ 1

=5-2*3+3
=5-6+3 {multiply 2 and 3}
=-1+3
=2
So, 2 is the answer.

+ 1

the Answer will be 2 positive

+ 1

yeah it's 2 as firstly -2*3= -6 and then 5+3=8
so basically -6+8=2

+ 1

please help me clarify why is the addition operator not evaluated first?
=5-(2*3)+3
=5-(6+3)
=5-9
=-4??

+ 1

BODMAS should be applied I think so...

+ 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).

Hot today

Please help, any idea?

2 Votes

Loop question, I've tried everything that I knew I just don't know. Please help me solve it out

1 Votes

What is wrong? Error on test.

1 Votes

Help me solve this (using loop)

1 Votes

Help me wiht python

1 Votes

how can i flip any word with c++

0 Votes