C Maths:

In C language, we can use math library and perform various operations. This library provides us a wide range of mathematical functions for tasks such as trigonometry, logarithms, exponentiation, and many more. This library provides a set of mathematical functions that can be used for various mathematical operations.

Usage:

To use functions from math.h library, we need to include the header file at the top of the program using #include directive.
#include <math.h>

maths.c
#include <stdio.h>
#include <math.h>
  
int main() {
  int num = 16;
  int result = sqrt(num);
  printf("Square root is %d", result);
  return 0;
}

Functions in Math Library:

There are different functions which are already defined in math.h Library. We just have to call them in our code. Performing these functions by yourself can be challenging for us and will be time consuming. Therefore, we use these libraries to save our time and to reduce the chance of errors.

FunctionDescriptionCode
pow(x, y)It takes the power of x raised to y.
double result = pow(base, exponent);
sin(x)It calculates sin of x.
double sinValue = sin(x);
cos(x)It calculates cos of x.
double cosValue = cos(x);
tan(x)It calculates tan of x.
double tanValue = tan(x);
log(x)It calculates natural log of x.
double naturalLog = log(x);
log10(x)It calculates log of x with base 10.
double naturalLog = log10(x);
fabs(x)It calculates absolute value of floating point numbers.
double absoluteValue = fabs(x);
ceil(x)It rounds a number up to a nearest integer.
double ceilValue = ceil(x);
floor(x)It rounds a number down to a nearest integer.
double floorValue = floor(x);
round(x)It rounds a floating point number to a nearest integer.
double roundedValue = round(x);
fmin(x, y)It returns the minimum value among two floating point numbers.
double minValue = fmin(num1, num2);
fmax(x, y)It returns the maximum value among two floating point numbers.
double maxValue = fmax(num1, num2);

Note: Before using any function of math.h Library, do not forget to include math.h.