From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Get the order correct - C Tutorial
From the course: Complete Guide to C Programming Foundations
Solution: Get the order correct
(upbeat music) - [Instructor] I hope you appreciate the descriptive variable names used in the challenge exercise file. Programmers who write good code use names such as these. No confusion. Starting here, we're going to assign the variables. First, assign 12 to variable rooms. (computer keys clicking) Next, 16 to variable paintings. (computer keys clicking) And to variable sculptures, four. (computer keys clicking) To calculate the number of artifacts, I will craft this expression. (computer keys clicking) The calculation inside the parentheses happens first. The value of paintings is added to sculptures. Once this value's obtained, the equation works left to right, with rooms multiplied by the results of the operation in parentheses. Run to see the answer. The museum has 240 artifacts. If you omit the parentheses, rooms is multiplied by paintings first, and then the result is added to sculptures, which yields the incorrect result. Here you see the value 196, which isn't correct…
Contents
-
-
-
-
-
Working with math operators3m 13s
-
(Locked)
Challenge: Do some math50s
-
(Locked)
Solution: Do some math1m 47s
-
(Locked)
Using assignment operators1m 49s
-
(Locked)
Obeying the order of precedence3m 14s
-
(Locked)
Challenge: Get the order correct55s
-
(Locked)
Solution: Get the order correct1m 37s
-
(Locked)
Working with relational operators3m 48s
-
(Locked)
Using logical operators3m 58s
-
(Locked)
Understanding bitwise operators3m 44s
-
(Locked)
Shifting bits3m 13s
-
(Locked)
Exploring unary operators3m 3s
-
Chapter challenge: More math1m 8s
-
(Locked)
Chapter solution: More math2m 45s
-
-
-
-
-
-
-
-
-