Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function power in C which is given two inputs - an integer base and an i

ID: 3547144 • Letter: W

Question

Write a function power in C which is given two inputs -

an integer base and an integer exponent which returns the value of

base to the power of exponent


prototype of function:

int power(int base, int exponent);


Examples:

base is 3

exponent is 5

returns 3*3*3*3*3 = 243


base is 5

exponent is 4

returns 5*5*5*5 = 625


base is 2

exponent is 8

returns 2*2*2*2*2*2*2*2 = 256


Write a driver and test with the above data.


Below are three example executions:

Example Executions:


Please enter the base: 3

Please enter the exponent: 5

The answer is 243.


Please enter the base: 5

Please enter the exponent: 4

The answer is 625.



Please enter the base: 2

Please enter the exponent: 8

The answer is 256.



Explanation / Answer

#include<stdio.h>


int power(int base,int exponent);


int main()


{


int base,exponent,answer;


printf("Enter the base value ");


scanf("%d",&base);


printf("Enter the exponent value ");


scanf("%d",&exponent);


answer=power(base,exponent);


printf("the answer is %d",answer);


return 0;


}


int power(int base,int exponent)


{


int i,j=1;


for(i=1;i<=exponent;i++)


{


j=j*base;


}


return j;


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote