• educational: contribute to the formation of ideas about two-dimensional array and basic properties of square matrices; consider actions that can be performed on matrices; introduce typical algorithms for processing matrices in Pascal language; create conditions for developing the ability to solve algorithms with two-dimensional arrays;
  • developing:
  • create conditions for the development of skills to work in a limited period of time, the development of independent work skills, and the development of note-taking skills.
  • educational:
  • to promote the creation of psychological comfort for work in the classroom, the development of composure, a responsible attitude towards one’s work, and increased motivation for educational activities.

Lesson type: combined.

Teaching methods: lecture, independent work.

Forms of organization: frontal work, individual work.

Equipment: assignments for work in the classroom (individual cards, assignments on the computer), notes on the board.

During the classes:

1. Organizational moment.

Greetings.
The topic is reported.
Set lesson goals and objectives.

2. Updating the acquired knowledge

The main points of the previous topic are spoken orally: “One-dimensional arrays”. Frontal mini survey on basic definitions.

3. Goal setting, task setting:

  • define the concept of a two-dimensional array;
  • consider the notation form of a two-dimensional array
  • consider the basic properties of square matrices;
  • consider actions that can be performed on matrices;
  • get acquainted with typical matrix processing algorithms in Pascal;
  • create conditions for developing the ability to solve algorithms with two-dimensional arrays;
  • 4. Lecture

    Definition.

    A two-dimensional array is a collection of data in which each value depends on two numbers, which can be thought of as a column index in a matrix.

    Recording format

    <имя>: array[n_index_1..in_index_1, n_index_2 ..in_index_2] of <тип>

    A: array of integer;

    In order to use an array element, you must specify the array name and the index of the element. The first index corresponds to the row number, the second – to the column number. For example:

    for i:=1 to n do
    for j:=1 to n do
    a:= random(100);

    When initializing two-dimensional arrays, each line is enclosed in an extra pair of parentheses:

    const a:mas= ((2,3,1,0),
    (1,9,1,3),
    (3,5,7,0));

    The analogue of Pascal arrays in mathematics are matrices. A matrix in which the number of rows is equal to the number of columns is called square. A(n,n) – square matrix

    Basic properties of square matrices:

    1. Square matrices have a main and side diagonals. For example, for matrix A, the main diagonal contains elements 1,5 and 9, and the secondary diagonal contains elements 3, 5 and 7.

    i=j – elements are located on the main diagonal;
    i> j – elements are located below the main diagonal;
    i i?j – elements are located on the main diagonal and below;
    i+j= n+1– elements are located on the side diagonal;
    i+j< n+1– элементы расположены над побочной диагональю;
    i+j> n+1– elements are located under the side diagonal;

    2. A square matrix in which all elements, excluding elements of the main diagonal, are equal to zero, is called diagonal matrix

    3. A diagonal matrix in which all elements on the main diagonal are equal to 1 is called identity matrix

    4. If you swap the rows and columns in the matrix A (m,n), you get the matrix A t (m,n), which is called a transposed matrix.

    Basic operations that can be performed on matrices

    • sum up;
    • find the difference;
    • product of a matrix by a certain number;
    • product of two matrices.

    Typical matrix processing algorithms in Pascal

    1. Output of the matrix in the form of a table:
    2. for i:= 1 to n do
      begin
      for j:= 1 to m do
      write(a:4);
      writeln
      end;

    3. Using a generator random numbers:
    4. randomize;
      for i:=1 to m do
      begin
      for j:=1 to n do
      begin
      a:=random(100)-10;
      write(a:4);
      end;
      writeln;
      end;

    5. 2nd way to display the matrix in the form of a table:
    6. for i:= 1 to n do
      for j:= 1 to m do
      if j>m then write (a:4)
      else writeln(a:4);

    7. Summation of matrices:
    8. for i:= 1 to n do
      begin
      for j:= 1 to m do
      c:=a+ b
      end;

    9. Transposing a matrix is ​​a mirror image of its elements relative to the main diagonal. You can do this by entering new array:

    for i:= 1 to n do
    for j:= 1 to n do
    b=a;

    5. Primary control

    “Outline map” 2 options

    1 option

    1. Correct inaccuracies in the description of a two-dimensional array:
    2. Var
      A= array of integer;

      ... ... of two-dimensional arrays, each line is enclosed in an additional pair of parentheses:

      const a:mas= ((2,3,1,0),
      (1,9,1,3),
      (3,5,7,0));

    3. Fill in the missing definitions:
    4. The main operations that can be performed on matrices are: summation, product of two matrices,….,….

    5. Fill in the missing definitions:
    6. A matrix whose number of rows is equal to the number of columns is called.... ….. .

    7. Find errors in the algorithm:

    for i:= 1 to n do
    begin
    for j:= 1 to m do
    c:=a+ a
    end;

    Option 2

    1. Correct inaccuracies in the array description:

    const
    n=4; m=3;
    type
    mas:array of integer;

    1. Fill in the missing definitions:
    2. ...... is a collection of data, each value of which depends on two numbers, which can be considered as the index of a column in a matrix.

    3. Fill in the missing definitions:
    4. A diagonal matrix in which all elements on the main diagonal are equal to ... is called identity matrix

    5. Fill in the missing definitions:
    6. A square matrix in which all elements, excluding elements of the main diagonal, are equal to zero, is called … … .

    7. Find errors in the algorithm:

    randomize;
    for i:=1 to m do
    begin
    for j:=1 to n do
    begin
    a:=random(100)-10;
    end;
    end;

    What typical task does the algorithm perform?

    Algorithms in Pascal language

    1. Write a program that, for a 3x4 integer matrix, determines the arithmetic mean of its elements and the number of positive elements in each row. Appendix 2
    2. program average_n;
      const m=3;
      n= 4;
      var

      i,j,n_pos_el:integer;
      medium:real;
      begin
      for i:=1 to m do
      for j:=1 to n do read(a);
      sred:=0;
      for i:=1 to m do begin
      n_pos_el:=0;
      for j:=1 to n do begin
      sred:=sred+a;
      if a>0 then inc(n_pos_el);
      end;
      writeln("V",i,"-oi stroke",n_pos_el,"polozitelnix elementov");
      end;
      sred:=sred/m/n;
      writeln("Srednee arifmeticheskoe:",sred:6:2);
      end.

    3. Write a program that, for a 3x4 rectangular integer matrix, determines the number of the leftmost column containing only positive elements. If there is no such column, a message is displayed. Appendix 3

    program num_posit;
    const m=3;
    n=4;
    var
    a: array of integer;
    i,j,num:integer;
    all_posit:boolean;
    begin
    randomize;
    for i:=1 to m do
    begin
    for j:=1 to n do
    begin
    a:=random(100)-10;
    write(a:4);
    end;
    writeln;
    end;
    num:=0;
    for j:=1 to n do begin
    all_posit:=true;
    for i:=1 to m do
    if a< 0 then
    begin
    all_posit:=false;
    break; end;
    if all_posit then begin
    num:=j; break; end;
    end;
    if num = 0 then
    writeln("Takix stolbcov net")
    else
    writeln("Number column:",num);
    end.

    Students upload files in Pascal, analyze these algorithms, view the results of program execution, and answer additional questions:

    1. How is a two-dimensional array organized?
    2. What does inc procedure mean?
    3. What does the break procedure mean?
    4. How is a random number generator used?

    6. Formation of problem solving skills.

    Solving problems on individual cards independently, in an algorithmic environment.

    Examples of tasks:

    1. Given a 5x5 matrix A containing random elements. Find the sum of all matrix elements.
    2. Display the Pythagorean table.
    3. Find the sum of positive elements of the specified column of matrix A of 5x5 integers.

    7. Lesson summary, homework assignment.

    Summarizing. Assessment of the level of assimilation.

    D/Z summary, tasks:

    For all:

    1. Given a two-dimensional square array. Find the numbers of rows whose all elements are equal to zero.
    2. Given a two-dimensional square array. Find the line numbers, the elements in each of which are the same.
    3. Determine the minimum element of a two-dimensional array. Print the line number containing maximum number minimum elements, if any.
    4. Given a two-dimensional array. Find the row with the largest sum of elements and the smallest. Display the found strings and the sums of their elements.

    For students who have an understanding of two-dimensional arrays and how to solve them:

    Instead of a lecture - solving problems of increased complexity.

    Examples of tasks:

    1. Given a two-dimensional array. Convert it according to the following rule: make the row with number N into the column with number N, and the column into a row.
    2. In a two-dimensional array X, all numbers are different. In each line, the minimum element is selected, then the maximum is selected from among these numbers. Print the line number of the X array in which the selected number is located.
    3. Given a two-dimensional array. Find the greatest of the values ​​of the elements of the first and last row.
    4. Write a program that displays a two-dimensional array line by line from the keyboard and calculates the sum of its elements in columns.
    5. Write a program that calculates the sum of the diagonal elements of a square matrix.

    Example 3

    Given an integer two-dimensional array of dimensions n x m,find the smallest element of the array and the number of the line in which it is located.

    Block diagram:
    Program code:
    Var a: array of integer;
    i, j, m, n, min, k: integer;
    Begin
    Write(‘how many lines?’); Readln(n);
    Write(‘how many columns?’); Readln(m);
    For i:=1 to n do
    For j:=1 to m do
    begin
    write(‘a[‘,i,’,’,j,’]=’); readln(a); (2D array input)
    end;
    min:=a; (minimum element)
    k:=1; (line number)
    For i:=1 to n do
    For j:=1 to m do
    If a< min then
    begin
    min:=a; k:=i; (search for the minimum and “remember” the line number)
    end;
    Writeln('smallest number ',min,' is in ', k , ' line');
    End.

    Tasks

    1. . Find the sum and product of all array elements.
    2. Given an integer two-dimensional array, dimensions n x m. Find the sum and product of even elements.
    3. Given an integer two-dimensional array, dimensions n x m. Find the sum and product of elements that are multiples of 3 and 5.
    4. Given an integer two-dimensional array, dimensions n x m. Find the number of negative elements greater than -9.
    5. Given an integer two-dimensional array, dimensions n x m.
    6. Given an integer two-dimensional array, dimensions n x m
    7. Given an integer two-dimensional array, dimensions n x m
    8. Given an integer two-dimensional array, dimensions n x m. Find the arithmetic mean of all array elements.
    9. Given an integer two-dimensional array, dimensions n x m. Find out which number occurs first in which line - positive or negative.
    10. Given an integer two-dimensional array, dimensions n x m. Find out which line has an ascending or descending sequence.
    11. Given an integer two-dimensional array, dimensions n x m. Withdrawits elements whose indices are powers of two (1, 2, 4, 8, 16, ...).
    12. Given an integer two-dimensional array, dimensions n x m. Find the number of elements that are multiples of 7.
    13. Given an integer two-dimensional array, dimensions n x m. Display elements that are squares of a number.
    14. Given an integer two-dimensional array, dimensions n x m. Find the numbers of odd elements in even places.
    15. Given an integer two-dimensional array, dimensions n x m. Find the maximum and minimum. Swap them.
    16. Given an integer two-dimensional array, dimensions n x m. Replace all elements with their squares.
    17. Given an integer two-dimensional array, dimensions n x m. Replace all elements with their opposite values.
    18. Given an integer two-dimensional array, dimensions n x m. Swap the first and last elements.
    19. Given an integer two-dimensional array, dimensions n x m. Form a new array consisting of opposite corresponding elements.
    20. Given an integer two-dimensional array, dimensions n x m. Display those elements whose remainder when divided by m is equal to k.
    21. Results are entered test work 10 students. Determine the number of unsatisfactory, satisfactory, good, and excellent grades. Withdraw average rating received by students for the test.
    22. Enter grades of N students in K subjects. Determine and display the number of students who did not receive a single “5”.
    23. There are N students in the group, the students received four marks for the exam. Determine the number of unsuccessful students and the average score of the group.
    24. Given an integer two-dimensional array, dimensions n x m. Calculate the sum of numbers whose ordinal numbers are Fibonacci numbers.
    25. Given an integer two-dimensional array, dimensions n x m. Add the corresponding elements.

    Another batch of computer science problems for schoolchildren has arrived. This time we'll look at working with two-dimensional arrays in C++. These problems are quite interesting. And I liked most of them.

    Task No. 1

    Find the indices of the first occurrence of the maximum element.
    Input format
    The program receives array sizes n and m as input, then n lines of m numbers each. n and m do not exceed 100.
    Output format
    Print two numbers: the row number and the column number in which it stands largest element in a two-dimensional array. If there are several such elements, then the one with the smaller row number is displayed, and if the row numbers are equal, then the one with the smaller column number is displayed.

    Sample Input: 3 4 0 3 2 4 2 3 5 5 5 1 2 3 Sample Output: 1 2

    #include using namespace std; int main() ( int n, m; cin >> n >> m; int a; // reading for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; ) ) int max = a, max_i = 0, max_j = 0; for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] >max) ( max = a[i][j]; max_i = i; max_j = j; ) ) ) cout<< max_i << " " << max_j; return 0; }

    Task No. 2

    Given an odd number n not greater than 15. Create a two-dimensional array of n×n elements, filling it with "." (each element of the array is a string of one character). Then fill the middle row of the array, the middle column of the array, the main diagonal and the secondary diagonal with "*" characters. As a result, the "*" in the array should form an asterisk image. Display the resulting array on the screen, separating the array elements with spaces.

    Sample Input: 5 Sample Output: * . * . * . * * * . * * * * * . * * * . * . * . *

    #include using namespace std; int main() ( int n; cin >>< n; i++) { for (int j = 0; j < n; j++) { if (i == j || i == n - 1 - j || i == n / 2 || j == n / 2) a[i][j] = 1; else a[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i][j] == 0) cout << "." << " "; else cout << "*" << " "; } cout << endl; } return 0; }

    Task No. 3

    Given a number n not exceeding 100. Create an array of size n×n and fill it according to the following rule. The numbers 0 should be written on the main diagonal. On the two diagonals adjacent to the main diagonal, the numbers 1. On the next two diagonals, the numbers 2, etc.

    Sample Input: 5 Sample Output: 0 1 2 3 4 1 0 1 2 3 2 1 0 1 2 3 2 1 0 1 4 3 2 1 0

    #include #include using namespace std; int main() ( int n; cin >> n; int a; // processing for (int i = 0; i< n; i++) { for (int j = 0; j < n; j++) { a[i][j] = (int) abs(i - j); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << a[i][j] << " "; } cout << endl; } return 0; }

    Task No. 4

    Given a two-dimensional array and two numbers: i and j. Swap columns numbered i and j in the array.
    Input format
    The program receives as input array sizes n and m, not exceeding 100, then array elements, then numbers i and j.
    Output format
    Print the result.

    Sample Input: 0 1 Sample Output: 12 11 13 14 22 21 23 24 32 31 33 34

    #include #include using namespace std; int main() ( int n, m, x, y, temp; cin >> n >>< n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; ) ) cin >> x >> y; // processing for (int i = 0; i< n; i++) { temp = a[i][x]; a[i][x] = a[i][y]; a[i][y] = temp; } // вывод for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << a[i][j] << " "; } cout << endl; } return 0; }

    Problem #5

    Given a number n not exceeding 10, and an array of size n × n. Check if this array is symmetrical about the main diagonal. Print the word “YES” if the array is symmetric, and the word “NO” otherwise.

    Sample Input: 3 0 1 2 1 2 3 2 3 4 Sample Output: YES

    #include #include using namespace std; int main() ( int n; bool symmetric; cin >> n; int a; // filling for (int i = 0; i< n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; ) ) // processing symmetric = true; for (int i = 0; i< n; i++) { for (int j = 0; j < n; j++) { if (a[i][j] != a[j][i]) symmetric = false; } } // вывод if (symmetric) cout << "YES"; else cout << "NO"; return 0; }

    Problem #6

    Given a square two-dimensional array of size n × n and a number k. Output the elements of the kth diagonal below the main diagonal (i.e. if k = 1, then you need to output the elements of the first diagonal lying below the main one, if k = 2, then the second diagonal, etc.).
    The value of k can be negative, for example, if k = −1, then you need to display the value of the first diagonal lying above the main one. If k = 0, then you need to output the elements of the main diagonal.
    The program receives as input the number n, not exceeding 10, then an array of size n × n, then the number k.

    Sample Input 1: 4 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 1 Sample Output 1: 5 1 6 Sample Input 2: 4 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 -2 Sample Output 2: 3 8

    #include using namespace std; int main() ( int n, k; cin >> n; int a[n][n]; // filling for (int i = 0; i< n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; ) ) cin >> k; // processing and output for (int i = 0; i< n; i++) { for (int j = 0; j < n; j++) { if (i - j - k == 0) cout << a[i][j] << " "; } } return 0; }

    Problem No. 7

    Given a two-dimensional array of size n×m (n and m do not exceed 1000). An array symmetric to it relative to the main diagonal is called transposed to the given one. It has dimensions m×n: the rows of the original array become the columns of the transposed one, the columns of the original array become the rows of the transposed one.
    Given an array, construct a transposed array and display it on the screen.

    Sample Input: 3 4 11 12 13 14 21 22 23 24 31 32 33 34 Sample Output: 11 21 31 12 22 32 13 23 33 14 24 34

    #include using namespace std; int main() ( int n, m, x, y, temp; cin >> n >>< n; i++) { for (int j = 0; j < m; j++) { cin >> < n; i++) { for (int j = 0; j < m; j++) { b[j][i] = a[i][j]; } } // вывод for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << b[i][j] << " "; } cout << endl; } return 0; }

    Problem No. 8

    There are n rows of cinema with m seats each (n and m do not exceed 20). A two-dimensional array stores information about sold tickets, the number 1 means that a ticket for a given seat has already been sold, the number 0 means that the seat is free. A request has been received to sell k tickets for adjacent seats in the same row. Determine whether this request can be completed.
    Input format
    The program receives numbers n and m as input. Next comes n lines containing m numbers (0 or 1), separated by spaces. Then the number k is given.
    Output format
    The program should print the number of the row in which there are k consecutive empty seats. If there are several such rows, then print the number of the smallest suitable row. If there is no suitable row, print the number 0.

    Sample Input: 3 4 0 1 0 1 1 0 0 1 1 1 1 1 2 Sample Output: 2

    #include using namespace std; int main() ( int n, m, k, r = 0; cin >> n >> m; int a[n][m]; // filling for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; ) ) cin >> k; // processing for (int i = 0; i< n; i++) { int near_free = 0; for (int j = 0; j < m; j++) { if (a[i][j] == 0) { near_free++; if (near_free == k) { r = i + 1; break; } } else near_free = 0; } if (near_free == k) break; } // вывод cout << r; return 0; }

    Problem No. 9

    Given a rectangular array of size n×m. Rotate it 90 degrees clockwise, writing the result to a new m×n array.
    Input format
    Enter two numbers n and m, not exceeding 100, then an array of size n×m.
    Output format
    Print the resulting array. Separate numbers when outputting with one space.

    Sample Input: 3 4 11 12 13 14 21 22 23 24 31 32 33 34 Sample Output: 31 21 11 32 22 12 33 23 13 34 24 14

    #include using namespace std; int main() ( int n, m; cin >> n >> m; int a[n][m]; int b[m][n]; // filling for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; ) ) // processing for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { b[j] = a[i][j]; } } // вывод for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << b[i][j] << " "; } cout << endl; } return 0; }

    Problem No. 10

    Given the numbers n and m, fill a two-dimensional array of size n×m with numbers from 1 to n×m “snake”, as shown in the example.
    Input format
    Enter two numbers n and m, each of which does not exceed 20.
    Output format

    Sample Input: 3 5 Sample Output: 1 2 3 4 5 10 9 8 7 6 11 12 13 14 15

    #include using namespace std; int main() ( int n, m, c = 0; cin >> n >> m; int a[n][m]; // processing for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { c++; if (i%2 == 0) a[i][j] = c; else a[i] = c; } } // вывод for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] % 10 == a[i][j]) cout << " "; else if (a[i][j] % 100 == a[i][j]) cout << " "; else if (a[i][j] % 1000 == a[i][j]) cout << " "; cout << a[i][j]; } cout << endl; } return 0; }

    Problem No. 11

    Given the numbers n and m, fill a two-dimensional array of size n×m with numbers from 1 to n×m “diagonals”, as shown in the example.
    Input format

    Output format
    Output the resulting array, allocating exactly 4 characters for each element.

    Sample Input: 3 5 Sample Output: 1 2 4 7 10 3 5 8 11 13 6 9 12 14 15

    #include using namespace std; int main() ( int n, m, pos = 0, row = 0; cin >> n >> m; int a[n][m]; // processing int start_row = 0; int number = 1; for ( int min_row = 0; min_row< n; min_row++) { if (min_row >0) start_row = pos - 1; else start_row = 0; for (pos = start_row; pos< m; pos++) { row = min_row; for (int col = pos; col >= 0; col--) ( if (row< n) { a = number; number++; row++; } else break; } } } // вывод for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] % 10 == a[i][j]) cout << " "; else if (a[i][j] % 100 == a[i][j]) cout << " "; else if (a[i][j] % 1000 == a[i][j]) cout << " "; cout << a[i][j]; } cout << endl; } return 0; }

    Problem No. 12

    Numbers n and m are given. Fill an n × m array in a checkerboard pattern: cells of one color are filled with zeros, and cells of another color are filled with natural numbers from top to bottom, from left to right. The number 1 is written in the upper left corner.
    Input format
    Enter two numbers n and m, not exceeding 100.
    Output format
    Output the resulting array, allocating exactly 4 characters for each element.

    Sample Input: 3 5 Sample Output: 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8

    #include using namespace std; int main() ( int n, m, sm; cin >> n >> m; int a[n][m]; // processing int number = 1; for (int i = 0; i< n; i++) { for (int j = 0; j < m; j++) { a[i][j] = 0; } } for (int i = 0; i < n; i++) { if (i % 2 == 1) sm = 1; else sm = 0; for (int j = sm; j < m; j++) { a[i][j] = number; number++; j++; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] % 10 == a[i][j]) cout << " "; else if (a[i][j] % 100 == a[i][j]) cout << " "; else if (a[i][j] % 1000 == a[i][j]) cout << " "; cout << a[i][j]; } cout << endl; } return 0; }

    Problem No. 13

    Given the numbers n and m, fill a two-dimensional array of size n×m with numbers from 1 to n×m in a spiral starting from the upper left corner and twisting clockwise, as shown in the example.
    Input format
    Enter two numbers n and m, not exceeding 100.
    Output format
    Output the resulting array, allocating exactly 4 characters for each element.

    Sample Input: 4 5 Sample Output: 1 2 3 4 5 14 15 16 17 6 13 20 19 18 7 12 11 10 9 8

    #include using namespace std; int main() ( int n, m; cin >> n >> m; int a; for (int i = 0; i<= n + 1; i++) { for (int j = 0; j <= m + 1; j++) { a[i][j] = -1; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[i][j] = 0; } } int num = 0, row = 1, col = 0; while (num < n * m) { while (a == 0) { col++; num++; a = num; } while (a == 0) { row++; num++; a = num; } while (a == 0) { col--; num++; a = num; } while (a == 0) { row--; num++; a = num; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] % 10 == a[i][j]) cout << " "; else if (a[i][j] % 100 == a[i][j]) cout << " "; else if (a[i][j] % 1000 == a[i][j]) cout << " "; cout << a[i][j]; } cout << endl; } return 0; }

    0 0

    Please enable JavaScript to view the

    Given a two-dimensional 5x5 array. Organize input of elements and output of results in the form of windows. After a pause, change the color of the windows in which the elements specified according to the condition are stored.

    Task options:

    1.

    2.

    3.

    4.

    5.

    6.

    7.

    8.

    9.

    10.

    11. Find the product of the elements that are above the main diagonal. Replace all odd elements with the found number.

    12. Find the sum of elements that are in odd positions (the sum of indices (i+j) for X ij is an odd number). Replace all negative elements with the found number.

    13. Find the product of all elements that are on the main diagonal. Replace all elements of the fifth row and second column with the found number.

    14. Find the arithmetic mean of the elements on the main diagonal and the arithmetic mean on the side diagonal. Swap the elements on the diagonals.

    15. Find the arithmetic mean of the positive elements that are above the main diagonal. Replace all negative elements with the found number.

    16. Find the sum of odd elements. Replace with the found number all the elements that are located above the side diagonal.

    17. Find the product of the elements of the i-row and j-column (i, j- first enter from the keyboard). Replace all elements below the secondary diagonal with the found number.

    18. Find the product of elements that are in even positions (the sum of the indices (i+j) for X ij is an odd number). Replace all elements on the main diagonal with the number found.

    19. Find the arithmetic mean of odd elements. Replace all elements of the secondary diagonal with the found number.

    20. Find the sum of all even elements that are above the secondary diagonal. Replace all elements of the fourth line with the found number.

    21. Find the product of the elements that are above the main diagonal. Replace all odd elements with the found number.

    22. Find the sum of elements that are in odd positions (the sum of indices (i+j) for X ij is an odd number). Replace all negative elements with the found number.

    23. Find the product of all elements that are on the main diagonal. Replace all elements of the fifth row and second column with the found number.

    24. Find the arithmetic mean of the elements on the main diagonal and the arithmetic mean on the side diagonal. Swap the elements on the diagonals.

    25. Find the arithmetic mean of the positive elements that are above the main diagonal. Replace all negative elements with the found number.

    For example: Find the arithmetic mean of elements on the main diagonal

    After a pause:

    Control questions

    1. What is text mode, and how does it differ from normal mode?

    2. What is a window?

    3. How to move the cursor to the specified window coordinates?

    4. How to change the font/background color?

    Introduction

    Modern technical devices intended for control and automation widely use binary circuits and the binary number system. The theory of logic algebra is used to analyze and synthesize combinational and sequential switching circuits.

    The lecture material is presented in three chapters. The first chapter gives the basic concepts of the theory of logical algebra and examines various forms of representing Boolean functions. The second chapter is devoted to the issues of minimizing representations of Boolean functions, which is the basis for the abstract synthesis of discrete devices. The third chapter contains information about methods for implementing Boolean functions based on switching circuits, which is the basis for the structural synthesis of discrete devices.

    When writing the lecture notes, the following literature was used: for section 1.1 - ; for section 1.2 – ; for section 1.3 – ; for section 2.1 – ; for section 2.2 – ; for sections 3.1, 3.2 – .