0
Java Program using Recursion to find the negative power of a number
Please help me in doing Java Program using Recursion to find the negative power of a number. For example: 5^(-2)=0.04
8 Answers
+ 3
What should I do now?
+ 2
Please send me the code because I had done that ,its not working
+ 2
LDSD Yes you are right its now working
+ 1
If you have done the positive side with recursion, and you understand how the negative powers work, then it should be quite easy to work with this.
input: number = any integer, power = negative integer
base/anchor: power is 0 returns 1
recursion: 1/number * function where power + 1
+ 1
Can you post what you have tried?
+ 1
Hmm, I just did your code in Python, and it worked.
I don't know much about Java yet, so perhaps the results have to do with something specific to the language. Specifically, every division (1/a) is returning 0.
(float numbers are weird.)
https://code.sololearn.com/cuPpnx1V0pMB/?ref=app
+ 1
SOUPTIK NATH
Nevermind I just noticed in my previous post. You are dividing (1/a) instead of (1.0/a)