Помогите пожалуйста реализовать функцию по преобразованию матрицы, думал

введите сюда описание изображения

Думал, нужно сделать просто из матрицы треугольную, но ошибся, теперь не понимаю как реализовать

Помогите, пожалуйста, вот мой код:

#include <iostream>
using namespace std;

void printTriangularMatrix(int arr[3][4]) {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            if (j >= i) {
                std::cout << arr[i][j] << " ";
            }
            else {
                std::cout << "0 ";
            }
        }
        std::cout << std::endl;
    }
}

int lesscounter(int arr[3][4], int num) {
    int count = 0;
    int sum = num;
    for (int i = 0; i < 3; i++) {
        if ((sum / 4) < num)
            count += 1;
        for (int j = 0; j < 4; j++)
            sum += arr[i][j];
    }
    return count;
}


int main() {
    int matrix[3][4] = { {-2, 0, 4, 7},
                          {6, -8, 0, 5},
                          {0, -3, 4, 1} };

    cout << "Enter matrix";
    for (int i = 0; i < 3; i++) {
        cout << "\n";
        for (int j = 0; j < 4; j++) {
            cout << matrix[i][j] << " ";
        }

    }
    cout << "\n";
    cout << "Complete matrix" << endl;

    printTriangularMatrix(matrix);

    cout << lesscounter(matrix, 1);
    return 0;
}

Ответы (0 шт):