How many times is the print statement executed? 
Hello,
     I've gotten far on this exercise, with the following insight: 
Here is a matrix of examples (vertical-axis is n=1,2,3,4,5,6,7,8; horizontal-axis is k=1,2,3,4)
1: 1  1   1   1    
2: 2  3   4   5    
3: 3  6  10  15    
4: 4 10  20  35    
5: 5 15  35  70    
6: 6 21  56 126    
7: 7 28  84 210    
8: 8 36 120 330

Now, there is an obvious pattern among the numbers, being triangular numbers, sum of triangular numbers, sum of sum of triangular numbers, and so on. My question is:
Can you help me find closed form expressions for the sums of the entries:


*

*Down the columns

*Across the rows

*And for general n,k?


Thanks!

This is a standard "stars and bars" problem. 
For given $n\geq1$ and $k\geq1$ we have to count the number of $k$-tuples $(i_1,\ldots,i_k)$ such that
$$1\leq i_k\leq i_{k-1}\leq\ldots\leq i_2\leq i_1\leq n\ .$$
Each such $k$-tuple can be encoded as a $0$-$1$-sequence of length $n+k-1$ as follows: Begin by writing $n-1$ ones, or bars $|$, leaving enough space between them. These bars create $n$ spaces between them and at the ends. The spaces represent the numbers $1$, $2$, $\ldots$, $n$. For each $i_j$ we write a $0$ into the space corresponding to its value, making a total of $k$ zeros. Conversely: Given a $0$-$1$-sequence with exactly $n-1$ ones and $k$ zeros we can immediately read off the sequence $(i_1,\ldots,i_k)$ so encoded.
There are
$${n+k-1\choose k}$$
such sequences, and this is also the number of times the print command is executed in the quoted program.
