What is the proper way or step by step solution for int x = (5+3*5)%3+3*7; sorry getting confused, even though i know the answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the proper way or step by step solution for int x = (5+3*5)%3+3*7; sorry getting confused, even though i know the answer

please no negative comments thanks :) what is your answer ( why and how)

5th Apr 2017, 9:22 AM
paupau oviedo
paupau oviedo - avatar
6 Answers
+ 6
x = (5+3*5)%3+3*7 Step 1: Bracket Open x = 5+3*5 = 5 + 15 (First Product then sum) = 20 Step 2: x = 20 % 3 (Remainder) = 2 Step 3: x = 2 + 3*7 (First Product then sum) = 2 + 21 = 23 Answer is 23
5th Apr 2017, 9:30 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
It is solved according to precedence order (5+3*5) 3*5=15(*=1st precedence) 5+15=20(+=2nd precedence) 20%3(here % and * has same precedence but it has to be from left to right) so 20%3=2 2+3*7(* has higher precedence so multiplication has to be done) 2+21 answer==23
5th Apr 2017, 11:01 AM
Champs
0
so what is your answer?
5th Apr 2017, 9:32 AM
paupau oviedo
paupau oviedo - avatar
0
isn't 15%3 = 0 becoz there is no remainder in 15%3 and also i tried using int x=(5+3*5) % 3+3*7; in a compiler and the answer is 23 by the way already tried many steps to get 23 that's why im getting confused. ps: also tried it in w3school compiler and the answer is also 23.
5th Apr 2017, 9:45 AM
paupau oviedo
paupau oviedo - avatar
0
thanks man hahaha
5th Apr 2017, 9:47 AM
paupau oviedo
paupau oviedo - avatar
0
15+5=20 20%3=2
5th Apr 2017, 11:02 AM
Champs