Introduction to Computer Science - Fall Semester 1998/9 Exercise 3

Due: 7/1/1999

Some Matrices

Write a program that asks the user for a positive integer n, and prints the following n×n matrices on the screen:

1. The zero matrix.

2. The unit matrix.

3. The matrix with ones on both diagonals and zeros everywhere else.

For example:

Please enter the dimension of the matrices: 5
The 5x5 matrices are:
The zero matrix =
00000
00000
00000
00000
00000
The unit matrix =
10000
01000
00100
00010
00001
The X matrix =
10001
01010
00100
01010
10001

The program should check if the user entered a negative (or zero) number and output an error message.