pow math.h code example

Example 1: pow() c

int base = 3;
int power = 5;
pow(double(base), double(power));

Example 2: power func in c

The function pow() is used to calculate the power raised 
to the base value. It takes two arguments. It returns the
power raised to the base value. It is declared in 
“math.h” header file.

Example 3: pow without math.h

int pow(int base, int exp)
    {
      if(exp < 0)
        return -1;

        int result = 1;
        while (exp)
        {
            if (exp & 1)
                result *= base;
            exp >>= 1;
            base *= base;
        }

        return result;
    }

Example 4: pow() c

[Mathematics] xy = pow(x, y) [In programming]

Tags:

Cpp Example