Skip to content
Advertisement

More recursive method to print Pascal’s triangle

I’ll try to use a recursive method to print pascals triangle to the standard output. I started by making an iterative method to get an idea of ​​how I wanted the method to work. See the code below.

JavaScript

Javadoc and the signature of binom

JavaScript

Then i began to work on the recursive method. I can not use any class variable for printing – so I can not use a vector. I can not have any object, the class the methods are in, the two methods and main are the only methods I can implement. The biggest problem is that I can not save the variables that binom should use because they reset after each iteration. Now I have this code for printPascal:

JavaScript

Is there a way to make the method above more recursive – is there a way to take away the for-loop?

Advertisement

Answer

I hope this helps?

JavaScript

If you insist, this should work?

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement