#1




Recursive power(x,n) functionhi every one
i'm new to C++ i get a assignment that i need to wirte a recursive function for exponential i wrote a silpme one, and it works, then the teacher ask me to modify it she wrote this: "The "simple" algorithm does n1 multiplications but it is possible to compute x^n for n=16 in 4 multiplications. Modify your program to output also the value of counter. For x=2.0 and n=16, the output would be x=2 n=16 x^n=65536 multiplications=4 Hint: One way to calculate x8 is to calculate x · x · x · x · x · x · x · x which takes 7 multiplications. But x · x · x · x · x · x · x · x = (x · x · x · x)^2 = ((x · x)^2)^2 which can be computed with 3 multiplications." but i try a so many time, still dont get it. i need some help for this. here is my code The "simple" algorithm she said.. CPP / C++ / C Code:


#2




Re: recursive power(x,n) functioni can't edit my post, so i reply my new update
i can now do the 2^8 in 3 muliti. but still can't do 2^16 in 4 muliti.. here is the new code CPP / C++ / C Code:

#3




Re: Recursive power(x,n) functionHere's a hint (I'm not going to give away the answer since it's a school assignment).
(Notation: By x^y, I mean x to the y power, not the bitwise XOR operator). CPP / C++ / C Code:
__________________
www.blakefoster.com 
«
Previous Thread

Next Thread
»
Thread Tools  Search this Thread 
Rate This Thread  



Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
run script command on ns2.26  newbie06  Computer Software Forum  Linux  66  16Jan2010 11:53 
Flex and bison coding  lucky88star  C++ Forum  5  24Dec2007 12:57 
Need Help with input files.  Efferus  C++ Forum  2  24Nov2007 17:19 
recursive function for perfect numbers?  cancan  C Programming Language  6  19Nov2007 12:46 
[Include] Doublylinked List  dsmith  C Programming Language  6  14Apr2006 13:12 
Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The
All times are GMT 6. The time now is 15:32.