#include <stdio.h>
int matrixCompare( int , int *, int * ) ;
void printMatrixCompare( int , int *, int * ) ;
int main( void )
{
int matrixA[ 3 ] [ 3 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
int matrixB[ 3 ] [ 3 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
int matrixC[ 3 ] [ 3 ] = { 1 , 4 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
printMatrixCompare( 3 , * matrixA, * matrixB) ;
printMatrixCompare( 3 , * matrixA, * matrixC) ;
printMatrixCompare( 3 , * matrixB, * matrixA) ;
printMatrixCompare( 3 , * matrixB, * matrixC) ;
printMatrixCompare( 3 , * matrixC, * matrixA) ;
printMatrixCompare( 3 , * matrixC, * matrixB) ;
//2d matrix of size 3*3
//give 2 matrices of size 2*2 as example
// int matrixF[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
// int matrixG[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 10 } };
// 0 1 2
// 0 1 2 3
// 1 4 5 6
// 2 7 8 9
return 0 ;
}
int matrixCompare( int pSize, int * matrixA, int * matrixB)
{
int i;
for ( i = 0 ; i < pSize* pSize; i++ )
{
if ( * matrixA!=* matrixB)
{
if ( * matrixA < * matrixB)
return - 1 ;
else
return 1 ;
}
matrixA++;
matrixB++;
}
return 0 ;
}
void printMatrixCompare( int pSize, int * matrixA, int * matrixB)
{
int result = matrixCompare( pSize, matrixA, matrixB) ;
if ( result == 0 )
puts ( "Both matrices are equal." ) ; if ( result == - 1 )
puts ( "matrixA is smaller than matrixB" ) ; if ( result == - 1 )
puts ( "matrixA is greater than matrixB" ) ; }
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWF0cml4Q29tcGFyZShpbnQsIGludCAqLCBpbnQgKik7CnZvaWQgcHJpbnRNYXRyaXhDb21wYXJlKGludCwgaW50ICosIGludCAqKTsKCmludCBtYWluKHZvaWQpC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