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

Solution: Do some math - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

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…

Contents