• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Java direct Recursion

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to convert this mutual recursion prog into direct recursion. Any Help how to do this

class Arec {

int a;
int b;
static long h(int k)
{ a++;
if (k == 0) return 0;
else return h(k - 1) + i(k - 1);
}

static long i(int k)
{ b++;
if (k == 0) return 1;
else return h(k) * i(k - 1);
}


public static void main(String argv[])
{ int k;
for (k = 0; k< 4; k++)
{ a = 0;
b = 0;
System.out.println("\n h("+k+") = "+h(k)+", i("+k+") = "+i(k));

}
}

}
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Welcome to JavaRanch

UseCodeTags
By using code tag your code will be easier to read.
 
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Who inflicted that exercise on you?
Please tell us what you think you should do. In fact I think it is better with the two methods.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic