The C standard library provides mathematical functions for rounding, powers, roots, logarithms, trigonometry and floating-point calculations. Most are declared in <math.h>; abs() for integers is declared in <stdlib.h>.
<math.h> functions are linked with the math library, for example gcc program.c -lm.#include <math.h>
#include <stdio.h>
int main(void) {
double value = 5.7;
printf("floor: %.1f\n", floor(value));
printf("ceil : %.1f\n", ceil(value));
printf("sqrt : %.3f\n", sqrt(value));
return 0;
}
Output
floor: 5.0
ceil : 6.0
sqrt : 2.387
abs() for an integer absolute value.floor(), ceil(), round() or trunc() depending on the exact rounding rule required.fmod() for floating-point remainders; the % operator is for integer operands.sqrt() and log().Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.