pow() - Mathematical Function

How is Mathematical Function "pow()" used in C++?
How to find the power value of a number ?

Explanation

pow() is a Mathematical Function that returns the "base" value raised to the "exp" power. A domain error is triggered if the "base" value is "Zero" and the exponent is less than or equal to zero or if the "base" is negative and the exponent value is not an integer.

Syntax to find power of a number:


float pow ( float base, float exp);
float pow ( float base, int exp);
double pow ( double base, double exp);
long double pow ( long double base, long double exp);
double pow ( double base, int exp);
long double pow ( long double base, int exp);

Example :



#include <iostream.h>
#include <cmath.h>
int main()
{
cout << "2 to the power of 2 is:: " << pow(2,2) << endl;
cout << "4 to the power of 2 is:: " << pow(4,2) << endl;
return 0;
}

Result :

2 to the power of 2 is:: 4
4 to the power of 2 is:: 16

In the above example pow() is used to find the power of base value 2,4 raised to the power of 2.

C++ Tutorial


Ask Questions

Ask Question