Home | | Computer Science 11th std | Mathematical functions (math.h) - C++ Header Files and Built-in Functions

# Mathematical functions (math.h) - C++ Header Files and Built-in Functions

Most of the mathematical functions are defined in math.h header file which includes basic mathematical functions.

Mathematical functions (math.h)

Most of the mathematical functions are defined in math.h header file which includes basic mathematical functions.

## 1. cos() function

The cos() function takes a single argument in radians. The cos() function returns the value in the range of [-1, 1]. The returned value is either in double, float, or long double.

### Program 11.12

#include <iostream>

#include <math.h>

using namespace std;

int main()

{

double x = 0.5, result;

result = cos(x);

cout << "COS("<<x<<")= "<<result;

}

### Output:

COS(0.5)= 0.877583

## 2. sqrt() function

The sqrt() function returns the square root of the given value of the argument. The sqrt() function takes a single non-negative argument. If a negative value is passed as an argument to sqrt() function, a domain error occurs.

### Program 11.13

#include <iostream>

#include <math.h>

using namespace std;

int main()

{

double x = 625, result;

result = sqrt(x);

cout << "sqrt("<<x<<") = "<<result;

return 0;

}

sqrt(625) = 25

## 3. sin() function

The sin() function takes a single argument in radians. The sin() function returns the value in the range of [-1, 1]. The returned value is either in double, float, or long double.

## 4. pow() function

The pow() function returns base raised to the power of exponent. If any argument passed to pow() is long double, the return type is promoted to long double. If not, the return type is double. The pow() function takes two arguments:

base - the base value

exponent - exponent of the base

### Program 11.14

#include <iostream>

#include <math.h>

using namespace std;

int main ()

{

double base, exponent, result;

base = 5;

exponent = 4;

result = pow(base, exponent);

cout << "pow("<<base << "^" << exponent << ") = " << result;

double x = 25;;

result = sin(x);

cout << "\nsin("<<x<<")= "<<result;

return 0;

}

### Output:

pow(5^4) = 625

sin(25)= -0.132352

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
11th Computer Science : Chapter 11 : Functions : Mathematical functions (math.h) - C++ Header Files and Built-in Functions |