iew Find Navigate Editor Product Debug Source Control Window

iew Find Navigate Editor Product Debug Source Control Window Help My Mac Running ok ok A ok main() c main.c Ninclude

Solution

Your code went into infinite loop because of using 1<=e and not i<=e (Use mistyped it as 1). So when that is fixed, it works fine. Also I suggest using a long for storing the result since exponents tend to be bigger when you use higher e. I have re-written the code with long. Also please use %ld when printing long values using printf()

long integerpower(int b,int e)
{
   int i;
   long p=1;
   for(i=1;i<=e;i++)
   {
           p*=b;
   }
   return p;
}

======================

sample main using the above function

int main()
{
   int base=2,exponent=4;
   long p;
   p=integerpower(base,exponent);
   printf(\"%d to power %d=%ld\",base,exponent,p);
}

 iew Find Navigate Editor Product Debug Source Control Window Help My Mac Running ok ok A ok main() c main.c Ninclude SolutionYour code went into infinite loop

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site