Find the position of the given row in a 2 | C ++ implementation of the approach ; Function to find a row in the given matrix using linear search ; Assume that the current row matched with the given array ; If any element of the current row doesn 't  match with the corresponding element  of the given array ; Set matched to false and break ; ; If matched then return the row number ; No row matched with the given array ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int m = 6 , n = 4 ; int linearCheck ( int ar [ ] [ n ] , int arr [ ] ) { for ( int i = 0 ; i < m ; i ++ ) { bool matched = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( ar [ i ] [ j ] != arr [ j ] ) { matched = false ; break ; } } if ( matched ) return i + 1 ; } return -1 ; } int main ( ) { int mat [ m ] [ n ] = { { 0 , 0 , 1 , 0 } , { 10 , 9 , 22 , 23 } , { 40 , 40 , 40 , 40 } , { 43 , 44 , 55 , 68 } , { 81 , 73 , 100 , 132 } , { 100 , 75 , 125 , 133 } } ; int row [ n ] = { 10 , 9 , 22 , 23 } ; cout << linearCheck ( mat , row ) ; return 0 ; }