You are viewing a single comment's thread. Return to all comments →
Recursive way.
def pascal(col: Int, row: Int) : Int = { if (col == 0 || col == row) 1 else pascal(col - 1, row - 1) + pascal(col, row - 1) }
def main(args: Array[String]) { val N = scala.io.StdIn.readInt() for (row <- 0 to N - 1) { for (col <- 0 to row) { print(pascal(col,row) + " ") } print("\n") } }
Pascal's Triangle
You are viewing a single comment's thread. Return to all comments →
Recursive way.