From the course: C Essential Training
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Solution: Do some math - C Tutorial
From the course: C Essential Training
Solution: Do some math
(upbeat music) - [Instructor] For my solution I declared variables a and c as integers, but variable b is a float, that's because it's expression shown at line 11 involves division. And in the challenge Source Code, I set a hint at the printf statement in line 16 using the %f place-holder which indicates a floating-point value, I hope you picked up on this hint. Assignments in math are done starting at line 10, a is assigned 15, b is assigned the value of a divided by two. And if you didn't write 2.0 here, at floating-point value the result will be wrong, as the compiler interprets two by itself as an integer. And variable c is assigned to the value variable b multiplied by four which will be an integer value. I'll build and run my solution. a is 15, b is seven and a half and c is 30. If you obtained this results, you passed the challenge, but if you saw only seven as a result for variable b you probably didn't specify…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Working with math operators3m 3s
-
(Locked)
Challenge: Do some math49s
-
(Locked)
Solution: Do some math1m 29s
-
(Locked)
Using assignment operators1m 44s
-
(Locked)
Obeying the order of precedence3m 13s
-
(Locked)
Challenge: Get the order correct54s
-
(Locked)
Solution: Get the order correct1m 11s
-
(Locked)
Working with relational operators3m 39s
-
(Locked)
Using logical operators3m 49s
-
(Locked)
Understanding bitwise operators3m 36s
-
(Locked)
Shifting bits3m 18s
-
(Locked)
Exploring unary operators3m 44s
-
(Locked)
Challenge: Binary math1m 5s
-
(Locked)
Solution: Binary math2m 11s
-
-
-
-