Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

C Math Functions

Math Functions

You can access a range of math functions for performing various mathematical operations on numbers.

To utilize them, include the math.h header file in your program.

  #include <math.h>

Square Root

To determine the square root of a number, employ the sqrt() function.

Example

printf(“%f”, sqrt(16));

Round a Number

The ceil( ) function rounds a number upward to its nearest integer, while the floor( ) function rounds a number downward to its nearest integer, and both return the result.

Example

  printf(“%f”, ceil(1.4));
printf(“%f”, floor(1.4));

Power

The pow() function yields the result of raising x to the power of y (xy).

Example

printf(“%f”, pow(4, 3));

Other Math Functions

Below is a table listing other commonly used math functions available in the <math.h> library:

Function

Description

abs(x)

Retrieves the absolute value of x

acos(x)

Retrieves the arccosine of x

asin(x)

Retrieves the arcsine of x

atan(x)

Retrieves the arctangent of x

cbrt(x)

Retrieves the cube root of x

cos(x)

Retrieves the cosine of x

exp(x)

Retrieves the value of Ex

sin(x)

Retrieves the sine of x (x is in radians)

tan(x)

Retrieves the tangent of an angle