Practice Sheet 2
Practice Sheet 2
Note: For all the questions, the pattern should be general, i.e. the number of rows or
columns should be variable and not constant.
b. 1
23
456
7 8 9 10
c. 1
121
12321
1234321
d. * * * * *
****
***
**
*
**
***
****
*****
e. 1 1 1 1 1
10001
10001
10001
11111
Pascal’s Triangle is a triangular array of binomial coefficients in which the nth row
contains binomial coefficients nC0, nC1, nC2, ……. nCn.
5. The first line of input is a number n, followed by n rows each containing n numbers,
signifying a nXn square matrix of numbers. Write the code to compute the trace of
the matrix (sum of diagonal elements)