Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

recursion problem

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all !
This program calculates the power of a number using recursion.
if i set the initial value of ans(the local variable in the method power)
other than 1 , things get messed up why???
One other thing.
I'm using the following stmt
ans=base1*power(base1,power1-1);
But even if i use
ans*=base1*power(base1,power1-1);
I get same answer.

But i guess the best approach is to simply return the expresion
return base1*power(base1,power1-1);

Thanks in advance
--Danish

[ Jess added UBB [code] tags to preserve whitespace ]
[ October 31, 2002: Message edited by: Jessica Sant ]
 
Fire me boy! Cool, soothing, shameless self promotion:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic