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

I\'m not too sure how to make an algorithm for this problem in a while loop. Do

ID: 2249050 • Letter: I

Question

I'm not too sure how to make an algorithm for this problem in a while loop.

Do problem 18 in section 3.9 of the text. Put your function pos_power() in the file exponent.c and the prototype in the file exponent.h.

Another useful debugging technique is to put debug lines into your functions to show when it is called, with what values are passed to it, and when the function returns with what value is being returned. Try using this technique for your function pos_power(). Put a printf() that looks like:

18. Write a function, float pos_power(float base, int exponent); which returns the value of base raised to a positive exponent. For example, if base is 2.0 and exponent is 3, the function should return 8.0. If the exponent is negative, the function should return 0.

Explanation / Answer

#include<stdio.h>

#include<math.h>

float pos_power(float base, int exponent);

float pos_power(float base, int exponent)

{

float Val;

float Expnt;

Expnt = exponent; //Type Casting

Val = pow(base,Expnt);

return(Val);

}

void main(void)

{

float fBase, Result;

int iExponent;

while(1)

{

printf("Enter the Base Value = "); scanf("%f",&fBase);

printf("Enter the Exponent = "); scanf("%d",&iExponent);

Result = pos_power(fBase, iExponent);

printf("%f^%d = %f",base,exponent,Result);

}

}