1#include <iostream>
2#include <cmath>
3using namespace std;
4int main ()
5{
6 double base, exponent, result;
7 base = 3.4;
8 exponent = 4.4;
9 result = pow(base, exponent);
10 cout << base << "^" << exponent << " = " << result;
11 return 0;
12}
1pow(base, exponent); //must #include <cmath> to use pow()
2
3example:
4
5#include <iostream>
6#include <cmath> //must include this library
7
8int main ()
9{
10 int y;
11 int x =10;
12 y = pow(x,2); // y = x^2
13}
1template<class T>T Pow(T n,T p)
2{
3 T res = n;
4 for(T i = 1; i < p; i++)
5 res *= n;
6 return res;
7}
8//Example: Pow(2,3) = 8