#K78072. Pascal's Triangle Generation
Pascal's Triangle Generation
Pascal's Triangle Generation
Given a non-negative integer (n), generate the first (n) rows of Pascal's Triangle. In Pascal's Triangle, each number is the sum of the two numbers directly above it. More formally, each element (T(i, j)) (0-indexed) is defined as:
[ T(i,j) = \begin{cases} 1 & \text{if } j = 0 \text{ or } j = i, \ T(i-1, j-1) + T(i-1, j) & \text{otherwise.} \end{cases} ]
If (n = 0), no output should be printed. The output should be printed to standard output with each row on a new line and numbers separated by spaces.
inputFormat
Standard Input (stdin) contains a single integer (n) ((n \ge 0)), representing the number of rows to generate.
outputFormat
Output (stdout) should contain (n) lines, where each line represents a row of Pascal's Triangle. Numbers in each row must be separated by a single space. If (n = 0), output nothing.## sample
5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
</p>