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.

Chapter solution: Adding variables and constants

Chapter solution: Adding variables and constants - C Tutorial

From the course: Complete Guide to C Programming Foundations

Chapter solution: Adding variables and constants

(upbeat music) - [Instructor] The first change I made for my solution is to create the constant. Remember, constants must be assigned a value right away as they're declared. Here, it's 3/4, which I'm writing is 0.75, and you could also write it this way. Either way is good, just remember to specify that decimal portion so that the compiler knows it's a floating point number. Next, declare three variables. The next set of comments are replaced with these variables assignments. You could assign any values, so don't be discouraged if you choose values different than mine. Still, the data types must match, single character, integer, floating point value. Finally, come a series of printf statements to output the values. The strings are partially built, so I'll take advantage of that as I convert these comments into C language statements. For a single character, use the %c placeholder. I've enclosed it in single quotes here, which is optional. For integers, use %d. For floating point values…

Contents