Download Tutorial C Files H Files

dg_pow

This function calculate the power of a number by n.

Usage

int dg_pow(int number, int pow);

Example

int dg_pow(10, 5);

Source code

int dg_pow(int number, int pow)
{
    int result = number;

    if (pow == 0)
        return 1;
    if (pow > 0)
        for (int i = 1; i < pow; i++)
            result *= number;
    else
        result = number / dg_pow(number, 1 - pow);
    return result;
}