Given a real positive number a and a nonnegative integer n .

Calculate a^n without using cycles and the function math.pow() , but using the recurrence relation a^n=a*a^(n-1) .

Closed due to the fact that the essence of the question is not clear by the participants Alexey Shimansky , Kromster , Denis , user194374, jmu 26 Dec '16 at 11:39 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • five
    Show your achievements and tell what is wrong with them - YuriySPb ♦
  • Weak in recursion, because I could not even imagine how it could be implemented, therefore I asked here) - Marat Zimnurov

1 answer 1

 private double pow(double a, int n) { if (n == 0) { return 1; } return pow(a, n-1)*a; } 

But do not forget about the range of values ​​for double .

  • Did you read the question? Topikstarter explicitly requests not to use pow ! - AK ♦
  • 2
    Did you watch the code? :) - Barmaley
  • @AK, Yes, I read. Where do you see the use of the Math.pow(...) method? - post_zeew
  • @Barmaley, What is the code? - post_zeew
  • @Barmaley thanks) - Marat Zimnurov