1 Replies - 941 Views - Last Post: 01 March 2014 - 12:36 PM Rate Topic: -----

#1 Varman   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-March 14

write a recursive program of rational numbers in java

Posted 01 March 2014 - 12:22 PM

the rational number program can't be found in net
Given below is sequence of rational numbers

1,2,5/2,29/10,941/290,969581/272890.......

Implement a recursive function for the above sequence

if n=0,then the answer is=1.

if n>0

f(n)=f(n-1)+1/f(n-1)
I can't develop a coding for the above function.. can anyone help me to solve in java?
Is This A Good Question/Topic? 0
  • +

Replies To: write a recursive program of rational numbers in java

#2 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11040
  • View blog
  • Posts: 18,855
  • Joined: 19-March 11

Re: write a recursive program of rational numbers in java

Posted 01 March 2014 - 12:36 PM

For any recursive function, the first step is to determine your base case and your inductive step. Start by writing those out in pseudocode, and then try to implement them.

You might want to write a little Rational class to help you out here. Since you're going to have to implement rational arithmetic in some fashion, you might as well try encapsulating it in a class. However, that's not strictly necessary - you can do without it if you want.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1