Untitled

 avatar
ketronix
c_cpp
2 years ago
1.0 kB
2
Indexable
Never
#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][m];
    cout << "Enter the elements of the matrix: " << endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> matrix[i][j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j < m; j++)
        {
            if (matrix[i][j] > 0)
            {
                count++;
            }
        }
        if (count % 2 == 0)
        {
            for (int j = 0; j < m; j++)
            {
                if (matrix[i][j] == 0 && j % 2 != 0)
                {
                    matrix[i][j] = 1;
                }
            }
        }
    }
    cout << "The result is: " << endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}