From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Solution: Do some math - C Tutorial
From the course: Complete Guide to C Programming Foundations
Solution: Do some math
(upbeat music) - [Instructor] Let me code a solution. Variables A and C can be integers because the math operations don't involve divisions. (keys tapping) Variable B however, must be a float because it's used in division. (keys tapping continues) In the challenge source code file, I set a hint here in the second print F statement where you see this, the percent F placeholder. This indicates a floating point value, and I hope you picked up on this hint. Next come the variable assignments and all the math as outlined in the challenge. (keys tapping) A is assigned the value 15 (keys tapping continues) B is assigned the value of variable A divided by 2, and I've used floating point notation for the literal here 0.0. The 0.0 causes the compiler to interpret the value as a real number, (keys tapping) and variable C is assigned the value of variable B multiplied by 4, which again can be an integer. I'll run my solution. And the proper output shows A is 15, B is 7.5, and C is 30. If you…
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
-
-
-
-
-
-
-
-
-