Find a way to fill matrix with 1 ' s ▁ and ▁ 0' s in blank positions | C ++ implementation of the approach ; Function to generate and print the required matrix ; Replace the ' . ' ; Toggle number ; For each row , change the starting number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define N  2 NEW_LINE #define M  2 NEW_LINE void Matrix ( char a [ N ] [ M ] ) { char ch = '1' ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( a [ i ] [ j ] == ' . ' ) a [ i ] [ j ] = ch ; ch = ( ch == '1' ) ? '0' : '1' ; cout << a [ i ] [ j ] << " ▁ " ; } cout << endl ; if ( i % 2 == 0 ) ch = '0' ; else ch = '1' ; } } int main ( ) { char a [ N ] [ M ] = { { ' . ' , ' _ ' } , { ' _ ' , ' . ' } } ; Matrix ( a ) ; return 0 ; }