top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Implement power function using C/C++?

0 votes
95 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ć
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...