top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Implement power function using C/C++?

0 votes
377 views

Implement power function using C/C++? The function should take two numbers as input (e.g. 2,3) and return 8 as output which is 2^3?

posted May 24, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Just multiply the number with itself so many times (assuming the power part is a integer)

int power_function(int number,int potencion)
{
    int number_cpy = number;
    int i = 1;

    while(i != potencion)
    {
        number = number*number_cpy;
        i++;    
    }

    printf("%d",number);
    return number;
}
answer May 24, 2017 by Leon Martinović
...