Lesson 9.Two-dimensional lists (arrays)
Problem «Maximum»
Statement
Given two integers representing the rows and columns \( \left ( m \times n \right ) \), and subsequent \( m \) rows of \( n \) elements, find the index position of the maximum element and print two numbers representing the index \( \left ( i \times j \right ) \) or the row number and the column number. If there exist multiple such elements in different rows, print the one with smaller row number. If there multiple such elements occur on the same row, output the smallest column number.Problem «Snowflake»
Statement
Given an odd number integer \( n \), produce a two-dimensional array of size \( \left ( n \times n \right ) \). Fill each element with a single character string of "."
. Then fill the middle row, the middle column and the diagnals with the single character string of "*"
(an image of a snow flake). Print the array elements in \( \left ( n \times n \right ) \) rows and columns and separate the characters with a single space.
Problem «Chess board»
Statement
Given two numbers \( n \) and \( m \). Create a two-dimensional array of size \( \left ( n \times m \right ) \) and populate it with the characters "."
and "*"
in a checkerboard pattern. The top left corner should have the character "."
.
Problem «The diagonal parallel to the main»
Statement
Given an integer \( n \), produce a two-dimensional array of size \( \left ( n \times n \right ) \) and complete it according to the following rules, and print with a single space between characters:- On the main diagonal write
0
. - On the diagonals adjacent to the main, write
1
. - On the next adjacent diagonals write
2
and so forth.
Print the elements of the resulting array.
Problem «Side diagonal»
Statement
Given an integer \( n \), create a two-dimensional array of size \( \left ( n \times n \right ) \) and populate it as follows, with spaces between each character:- The positions on the minor diagonal (from the upper right to the lower left corner) receive
1
. - The positions above this diagonal recieve
0
. - The positions below the diagonal receive
2
.
Print the elements of the resulting array.
Problem «Swap the columns»
Statement
Given two positive integers \( m \) and \( n \), \( m \) lines of \( n \) elements, giving an \( m \times n \) matrix \( A \), followed by two non-negative integers \( i \) and \( j \) less than \( n \), swap columns \( i \) and \( j \) of \( A \) and print the result.Write a function swap_columns(a, i, j)
and call it to exchange the columns.