0

Why does 5-3*3+3 equals 2 in ruby

ruby operators

28th Jan 2017, 7:01 PM
akirkham
akirkham - avatar
6 odpowiedzi
+ 2
because of operator precedence . it's same in all languages. it's rule of maths.! 5-3*3+3 ... first multiplication/division it will be => 5-9+3 then addition/substraction => -1
28th Jan 2017, 7:10 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
+ 1
@VEdward, that equals -1... @akirkham What code are you using to come to that answer?
28th Jan 2017, 7:25 PM
Blightedsage
Blightedsage - avatar
0
yeah that's right.. it should be -1! my bad -,3
28th Jan 2017, 7:28 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
0
https://code.sololearn.com/c3weD5Y62u52/?ref=app check this code... it's giving -1 as answer in Ruby
28th Jan 2017, 7:30 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
0
that is why I posted solos try it comes to 2 I didn't think it was correct
28th Jan 2017, 8:09 PM
akirkham
akirkham - avatar
0
man I checked it...it's giving -1 as answer
28th Jan 2017, 8:23 PM
Pankaj Vaghela
Pankaj Vaghela - avatar