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

26th Feb 2020, 4:35 PM
Souptik Nath
Souptik Nath - avatar
8 ответов
+ 3
What should I do now?
26th Feb 2020, 5:36 PM
Souptik Nath
Souptik Nath - avatar
+ 2
Please send me the code because I had done that ,its not working
26th Feb 2020, 5:01 PM
Souptik Nath
Souptik Nath - avatar
26th Feb 2020, 5:07 PM
Souptik Nath
Souptik Nath - avatar
+ 2
LDSD Yes you are right its now working
26th Feb 2020, 5:43 PM
Souptik Nath
Souptik Nath - avatar
+ 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
26th Feb 2020, 4:52 PM
LDSD
LDSD - avatar
+ 1
Can you post what you have tried?
26th Feb 2020, 5:02 PM
LDSD
LDSD - avatar
+ 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
26th Feb 2020, 5:29 PM
LDSD
LDSD - avatar
+ 1
SOUPTIK NATH Nevermind I just noticed in my previous post. You are dividing (1/a) instead of (1.0/a)
26th Feb 2020, 5:40 PM
LDSD
LDSD - avatar