C Maths

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

Functions in Math Library

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

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

Note: Before using any function in Math Library, remember to include math.h.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which of the following is a best practice in programming?

10 XP~2 min
Exercise 2 of 2Easy

Code that is easy to read and understand is called ___ code.

10 XP~2 min