About Operations | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

About Operations

In my programming book, I have a question: x= 7 + 2 * 6 / 3 - 1; Show the value of the x after each operation has completed. But the problem is that I don't have a value of x after each operation. Because there are many operations that have to complete.

20th Sep 2017, 6:41 PM
Yusuf
Yusuf - avatar
1 Answer
+ 3
7 + 2 is one operation. Basically they're testing if you know the order of operations. So, go in the order that YOU would solve it mathematically, and after each operation give the -current- answer before you move to the next operation. Get what I mean? For example, if it was x = 2 + 2 * 2 / 2 - 2; I would go 2 + 2 = 4, okay x is 4, and then move on from there. (Don't use my example. I'm aware of order of operations. :D ) In this scenario, you would go 7 + 2 and get the answer before you move to the next operation. However, use what you've learned in math class to understand the order it'll take. This is an important lesson, and shows the importance of parenthesis also. I forgot how it goes, but I think in school they use the whole "My Dear Aunt Sally" symbolism to remember the order. ;) ;) ;)
20th Sep 2017, 6:54 PM
AgentSmith