Exercise 3: Making Matrix Using Arrays

Display a matrix of zeros and ones by using a two-dimensional array.

Problem statement

Write a display function that takes an integer size, creates a 2D matrix of the specified size, and displays this matrix.

  • The diagonal of the matrix should be filled with 0.

  • The lower side of the diagonal should be filled with -1s.

  • The upper side of the diagonal should be filled with 1s.

Sample input

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy