Untitled

 avatar
ketronix
c_cpp
3 years ago
1.2 kB
4
Indexable
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cout << "Enter the number of rows and columns in the matrix: ";
    cin >> n >> m;
    int matrix[n][n];
    srand(time(NULL));
    //заполнение какими-то данными
    for (int i = 0; i < n; i++)
    {
        for (int m = 0; m < n; m++)
        {
            matrix[i][m] = rand() % 40-20;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j < n; j++)
        {
            if (matrix[i][j] > 0)
            {
                count++;
            }
        }
        if (count % 2 == 0)
        {
            for (int j = 0; j < n; j++)
            {
                if (j % 2 != 0)
                {
                    matrix[i][j] = 1;
                }
            }
        }
    }
    cout << "The result is: " << endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
Editor is loading...