Advertisement

Basic Algor

Started by October 15, 2000 09:59 AM
3 comments, last by StephenNitro 24 years, 2 months ago
Need help on another problem for the Deitel & Deitel C++ Ed2, write a function integerPower( base , exponent ) that returns the value for example integerPower( 3 , 4 ) = 3*3*3*3 .. do not use any math library functions.. use a for or while loop to control the calculation Cheers Stephen and if poss tell me how easy you found the problem and what experience you have.. its just a guide Edited by - StephenNitro on 10/15/00 10:07:29 AM
something like this...


void int integerPower(base, exponent)
{
if (exponent == 0)
return 1;
else if (exponent == 1)
{
return (base += base);
else
return (base += integerPower(base, exponent - 1));
}

I hope this is it.

Bye

Rooster
CR
Advertisement
Sorry mate that didn''t work for me.. also i need it with a for or while loop not a recursive function

Cheers for the help though
int IntegerPower (int x, int y)
{
int r = 1;
for (i = 0; i < y; i++)
r *= x;

return r;
}

Is that all you wanted?


_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Cheers bishop, works fine now..
In my version that wasn''t working the r was set to 0

Thanks for help

Cheers

Nitro

This topic is closed to new replies.

Advertisement