What is the pow() function in C++?

The pow() function computes a base number raised to the power of an exponent.

Syntax

The pow() function takes two arguments, a base and an exponent. Both of these arguments have to be of type double.

double result = pow(base, exponent); 

Code

The code below illustrates the use of the pow() function.

#include <iostream>
using namespace std;
#include <bits/stdc++.h>
int main() {
cout<<"4 ^ 3 = "<< pow(4.0, 3.0)<<endl;
cout<<"2.65 ^ 4.5 = "<< pow(2.65, 4.5)<<endl;
return 0;
}

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved