C Math Functions

C programming language provides several built-in math functions in the math.h library that perform various mathematical operations. These functions can be useful in many different types of programs, such as scientific, engineering, and financial applications.

Here are some of the commonly used math functions in C:

  1. abs(): calculates the absolute value of an integer or a floating-point number.
int abs(int x);
double fabs(double x);
  1. sqrt(): calculates the square root of a non-negative number.
double sqrt(double x);
  1. pow(): calculates the power of a number.
double pow(double x, double y);
  1. floor(): rounds a floating-point number down to the nearest integer.
double floor(double x);
  1. ceil(): rounds a floating-point number up to the nearest integer.
double ceil(double x);
  1. sin(), cos(), tan(): calculates the trigonometric functions of an angle measured in radians.
double sin(double x);
double cos(double x);
double tan(double x);
  1. log(), log10(): calculates the natural logarithm or the base-10 logarithm of a number.
double log(double x);
double log10(double x);
  1. exp(): calculates the exponential value of a number.
double exp(double x);

These are just some of the math functions available in C. To use these functions, you need to include the math.h header file in your program.

For example, to calculate the square root of a number, you can write:

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

int main() {
    double x = 16.0;
    double result = sqrt(x);
    printf("The square root of %.1f is %.1f\n", x, result);
    return 0;
}

This program would output: The square root of 16.0 is 4.0.

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

89473