Mathematical functions (math.h)
Most of the mathematical functions are defined in math.h header file which includes basic mathematical functions.
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.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double x = 0.5, result;
result = cos(x);
cout << "COS("<<x<<")= "<<result;
}
COS(0.5)= 0.877583
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.
#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
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.
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
#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;
}
pow(5^4) = 625
sin(25)= -0.132352
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.