Math Exp2 Function

C++ Math exp2

The function computes the base - 2 exponential function of a given number.

Suppose a number is 'x':

Example

exp2(x) = 2<sup>x</sup>

Syntax

Example

float exp2(float x);
double exp2(double x);
long double exp2(long double x);
double exp2(integral x);

Parameter

x : It is the value of the exponent.

Return value

It returns, 2 raised to the power x.

Example 1

Let's see a simple example when the value of x is positive

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
 int x= 4;
 std::cout << "Value of x is : " <<x <<std::endl;
 cout<<"exp2(x) = "<<exp2(4);
 return 0;
}

Output:

Output

Value of x is : 4
exp2(x) = 16

Example 2

Let's see a simple example when the value of x is negative.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
 int x= -2;
 std::cout << "Value of x is : " <<x <<std::endl;
 cout<<"exp2(x) = "<<exp2(x);
 return 0;
}

Output:

Output

Value of x is : -2
exp2(x) = 0.25

Input Required

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