Math Pow Function

C++ Math pow

This function is used to find the power of a given number.

Consider a base 'b' and exponent 'e'.

Syntax

Its syntax would be :

Example

double pow(double b, double e);
float pow(float b, float e);
long double pow(long double b, long double e);
promoted pow(type1  b, type2 e);

Note: If any argument is of long double type, then the return type is promoted to long double. If not, then the return type is promoted to double.

Parameter

b : 'b' is the number, whose power is to be calculated.

e : 'e' is the exponent.

Return value

It returns the base 'b'raised to the power 'e'.

Example 1

Let's see a simple example when both base and exponent are of integer type.

Example

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int base=4;
  int exponent=2;
  int power=pow(base,exponent);
  std::cout << "Power of a given number is :" <<power;
  return 0;
}

Output:

Output

Power of a given number is :16

Example 2

Let's see a example when base is of float type and exponent is of integer type.

Example

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
   int base=4.5;
  int exponent=3;
  int power=pow(base,exponent);
  std::cout << "Power of a given number is :" <<power;
  return 0;
}

Output:

Output

Power of a given number is :64

Example 3

Let's see a simple example when both base and exponent are of float type..

Example

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
   int base=2.5;
  int exponent=2.5;
  int power=pow(base,exponent);
  std::cout << "Power of a given number is :" <<power;
  return 0;
}

Output:

Output

Power of a given number is :4

Input Required

This code uses input(). Please provide values below: