Including math.h
Link and use the math library.
Why math.h Exists
C keeps its core language small. Operations like square roots, powers, and trigonometry are not built into the language itself.
Instead they live in a standard library header called math.h. To use these functions you must include the header at the top of your program.
Including the Header
Add this line near the top of your file, alongside stdio.h:
#include <stdio.h>for input/output#include <math.h>for math functions
Angle brackets tell the compiler to look in the standard system folders.
#include <stdio.h>
#include <math.h>
int main(void) {
printf("math.h is ready\n");
return 0;
}All lessons in this course
- Including math.h
- Powers and Roots
- Trig and Logarithms
- Rounding and Absolute Values