Find the intersection of two Matrices | CPP program to find intersection of two matrices ; Function to print the resultant matrix ; print element value for equal elements else * ; Driver Code
#include <bits/stdc++.h> NEW_LINE #define N  4 NEW_LINE #define M  4 NEW_LINE using namespace std ; void printIntersection ( int A [ ] [ N ] , int B [ ] [ N ] ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( A [ i ] [ j ] == B [ i ] [ j ] ) cout << A [ i ] [ j ] << " ▁ " ; else cout << " * ▁ " ; } cout << " STRNEWLINE " ; } } int main ( ) { int A [ M ] [ N ] = { { 2 , 4 , 6 , 8 } , { 1 , 3 , 5 , 7 } , { 8 , 6 , 4 , 2 } , { 7 , 5 , 3 , 1 } } ; int B [ M ] [ N ] = { { 2 , 3 , 6 , 8 } , { 1 , 3 , 5 , 2 } , { 8 , 1 , 4 , 2 } , { 3 , 5 , 4 , 1 } } ; printIntersection ( A , B ) ; return 0 ; }