Finding GCD of each row and column and replacing with each element with maximum of GCD of row or column .
void replacematrix ( int mat [ R ] [ C ] , int n , int m ) { int rgcd [ R ] = { 0 } , cgcd [ C ] = { 0 } ;