C provides a rich set of mathematical functions that can be used to perform various calculations. These functions are defined in the math.h header file.

Math Function In C

C Programming allows us to perform mathematical operations through the functions defined in <math.h> header file. The <math.h> header file contains various methods for performing mathematical operations such as sqrt(), pow(), ceil(), floor() etc.
 

Common Mathematical Functions

Here are some of the most commonly used mathematical functions in C:

  • Trigonometric functions:
    • sin(x): Calculates the sine of x (x in radians).
    • cos(x): Calculates the cosine of x (x in radians).
    • tan(x): Calculates the tangent of x (x in radians).
    • asin(x): Calculates the arcsine of x (-1 <= x <= 1).
    • acos(x): Calculates the arccosine of x (-1 <= x <= 1).
    • atan(x): Calculates the arctangent of x.
    • atan2(y, x): Calculates the arctangent of y/x.
    • Exponential and logarithmic functions:
      • exp(x): Calculates the exponential of x (e^x).

 

      • log(x): Calculates the natural logarithm of x (ln(x)).

 

    • log10(x): Calculates the base-10 logarithm of x (log10(x)).  
    • pow(x, y): Calculates x raised to the power of y (x^y).
    • sqrt(x): Calculates the square root of x.
  • Other functions:
    • ceil(x): Rounds x up to the nearest integer.
    • floor(x): Rounds x down to the nearest integer.
    • fabs(x): Calculates the absolute value of x.
    • fmod(x, y): Calculates the remainder of x divided by y.
    • hypot(x, y): Calculates the hypotenuse of a right triangle with legs x and y.

Math Function In C

Example:

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

int main() {
    double x = 3.14;

    printf("sin(x) = %fn", sin(x));
    printf("cos(x) = %fn", cos(x));
    printf("tan(x) = %fn", tan(x));
    printf("sqrt(x) = %fn", sqrt(x));
    printf("pow(x, 2) = %fn", pow(x, 2));

    return 0;
}

Note: These functions typically return double-precision floating-point values. You may need to cast the result to another data type if necessary.

C math functions are a set of standard library functions in the C programming language that perform mathematical operations, located in the ` ` header. These functions include basic operations such as `sqrt` for square root, `pow` for exponentiation, and `sin`, `cos`, `tan` for trigonometric calculations

Related Posts

Leave a Reply