From the course: C Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Rounding and truncating - C Tutorial
From the course: C Standard Library
Rounding and truncating
- [Instructor] Let's see some nearest integer functions in the C standard library. First we have round, which returns the closest integer value to the argument. The trunc function returns the truncated value. That is, the function returns the integer part of the argument. Next we have the ceiling and floor functions. Ceiling returns the smallest integer value not less than the argument. This may be used to calculate the hours to bill in a parking lot that only charges per hour. So if you stayed for 5.2 hours, you will be billed for six hours anyway. Finally, the floor function returns the largest integer value not greater than the argument. This is what people use to report the age of a person. For example, if someone is 23.7 years old, people just say 23.
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
-
-
-
-
-
-
-
Mathematical functions2m 50s
-
Rounding and truncating51s
-
Rounding and truncating example5m 4s
-
Trigonometric functions1m 42s
-
Trigonometric functions example1m 27s
-
Powers and exponentials1m 9s
-
Powers and exponentials example3m 4s
-
Challenge: Polar coordinate conversion2m 19s
-
Solution: Polar coordinate conversion6m 53s
-
C23 update3m 39s
-
-