Utilizor
Contact Us

CC Math

Math functions.

C Math

C provides many functions that allow you to perform mathematical tasks on numbers.

Math Header

To use these functions, you must add the #include <math.h> header file.

Common Functions

  • sqrt(x): Returns the square root of x
  • ceil(x): Rounds x upwards to the nearest integer
  • floor(x): Rounds x downwards to the nearest integer
  • pow(x, y): Returns the value of x to the power of y
  • abs(x): Returns the absolute value of x

Examples

Square Root

c example

Calculating square root.

#include <stdio.h>
#include <math.h>

int main() {
  printf("%f", sqrt(16));
  return 0;
}

Rounding

c example

Ceil and Floor functions.

#include <stdio.h>
#include <math.h>

int main() {
  printf("%f\n", ceil(1.4));
  printf("%f\n", floor(1.4));
  return 0;
}

Power

c example

4 raised to the power of 3.

#include <stdio.h>
#include <math.h>

int main() {
  printf("%f", pow(4, 3));
  return 0;
}

Test Your Knowledge

1. Which function returns the square root?

2. What does pow(2, 3) return?