C – Math Functions

As the name suggests, the Math Functions in C language are used to perform mathematical tasks such as returning the sine, cosine, cube root, absolute value, etc. To work on Math Functions in C language, use the following header file:

Include it in your program file:

Here are the popular math functions in C language and what they will return after execution:

  • sqrt(a): square root of a
  • exp(a): e raised to the power of a i.e., Ea
  • cos(a): cosine of a
  • sin(a): sine of a
  • tan(a): tangent of an angle
  • acos(a): arccosine of a
  • asin(a): arcsine of a
  • atan(a): arctangent of a
  • cosh(a): returns the hyperbolic cos of a
  • sinh(a): returns the hyperbolic sin of a
  • tanh(a):  returns the hyperbolic tangent of a

Let us now see the above math functions one by one with examples:

sqrt() in C Language

The sqrt() function in C is used to get the square root of a number.

Let us now see an example of the sqrt() function:

Output

When you run this program, it will calculate the square root of 25.0 and display the result. The output will be:

exp() in C Language

The exp() function in C is used to return e raised to the power of a.

Let us now see an example of the exp() function. Here, we are calculating e to the power 2.0:

Output

When you run this program, it will calculate the value of e raised to the power of 2.0 and display the result. The output will be:

cos() in C Language

The cos() function in C  returns the cosine of a. We will convert the angle from degrees to radians before passing it to the cos() function.

The #define is a preprocessor directive used to create symbolic constants. It allows you to define a constant value that can be used throughout your code, making your code more readable and maintainable.

The following defines a constant named PI with the value 3.14159265, which represents the mathematical constant π (pi). By using #define, you can use PI in your code instead of repeatedly typing 3.14159265:

Let us now see an example of the cos() function:

Output

sin() in C Language

The sin() function in C returns the sin of a. We have converted the angle from degrees to radians before passing it to the sin() function.

Let us now see an example of the sin() function:

Output

tan() in C Language

The tan() function in C is used to return the tangent of a. The tan() function in C expects the angle to be in radians, not degrees. We will convert the angle from degrees to radians before using the tan() function.

Let us now see an example of the tan() function:

Output

acos() in C Language

The acos() function in C returns the arc cosine of a in radians.

Let us now see an example of the acos() function:

Output

asin() in C Language

The asin() function in C  returns the arc sine of a in radians.

Let us now see an example of the asin() function:

Output

atan() in C Language

The atan() function in C  returns the arc tangent of a in radians.

Let us now see an example of the atan() function:

Output

cosh() in C Language

The cosh() function in C returns the hyperbolic cos of a.

Let us now see an example of the cosh() function:

Output

When you run this program, it will calculate the hyperbolic cosine of 2.5 and display the result. The output will be:

sinh() in C Language

The sinh() function in C  returns the hyperbolic sine of a.

Let us now see an example of the sinh() function:

Output

When you run this program, it will calculate the hyperbolic sine of 2.5 and display the result. The output will be:

tanh() in C Language

The tanh() function in C  returns the hyperbolic tangent of a.

Let us now see an example of the tanh() function:

Output

When you run this program, it will calculate the hyperbolic tangent of 2.5 and display the result. The output will be:

If you liked the tutorial, spread the word, and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

C Structures
C - Typecasting
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading