0% found this document useful (0 votes)
9 views2 pages

Practice Sheet 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Practice Sheet 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Nested Loops Practice Questions

Note: For all the questions, the pattern should be general, i.e. the number of rows or
columns should be variable and not constant.

1. Print the following patterns:


a. 5 4 3 2 1
4321
321
21
1

b. 1
23
456
7 8 9 10

c. 1
121
12321
1234321

d. * * * * *
****
***
**
*
**

***

****

*****

e. 1 1 1 1 1
10001
10001
10001
11111

2. Print the Floyd’s triangle:


1
01
101
0101
10101

3. Print the Pascal’s triangle:

Pascal’s Triangle is a triangular array of binomial coefficients in which the nth row
contains binomial coefficients nC0, nC1, nC2, ……. nCn.

4. Print your initials. For eg my initials:


***** *****
* * * *
* * * *
***** *****
* * *
* * *
* *****

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)

You might also like