c++ pow 10 code example
Example 1: pow c++
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
double base, exponent, result;
base = 3.4;
exponent = 4.4;
result = pow(base, exponent);
cout << base << "^" << exponent << " = " << result;
return 0;
}
Example 2: pow c++
template<class T>T Pow(T n,T p)
{
T res = n;
for(T i = 1; i < p; i++)
res *= n;
return res;
}
//Example: Pow(2,3) = 8