# C simple Matrices

• 05-07-2009
Cyberman86
C simple Matrices
i can't figure out the function part, although i tried i don't know if it makes sense, since I'm a beginner, how would you do it.

Write a function that takes two matrices as parameters (2D arrays, say
A[Ra][Ca], and B[Rb][Cb], where Ra, Ca, Rb, and Cb are predefined global constants).

Then your function should check if these two matrices are equal (same) or not. If so, it should return
1; otherwise, it should return 0.

Two matrices are said to be equal if and only if they have the same order (same number of rows and
same number of columns) and if the corresponding elements in both matrices are equal.
For example,

A=....4 2 5.................B=.....4 2 5
........5 1 3.........................5 1 3

These are 2 matrices but i Can't draw the boxes here.

Code:

```#include <stdio.h> int main() { int check_matrix_equality( int A[Ra][Ca], int B[Rb][Cb]) {      int i, j,;     int matrix [2] [3];         for (i = 0; i<2; i++)          for (j = 0; j < 3; j++)          {                matrix [ i ] [ j ] = i;               return 0; }```
• 05-07-2009
quzah
Code:

```for each row     for each column         if this spot in one is not equal to this spot in the other             return failure     return true```
Something like that is what you're looking for.

Quzah.
• 05-07-2009
Cyberman86
is it some like this?
Quote:

Originally Posted by quzah
Code:

```for each row     for each column         if this spot in one is not equal to this spot in the other             return failure     return true```
Something like that is what you're looking for.

Quzah.

Is it something like this?

Code:

``` #include <stdio.h> int main() { int check_matrix_equality( int A[Ra][Ca], int B[Rb][Cb]) {      int i, j,;     int matrix [2] [3];         for (i = 0; i<2; i++)          for (j = 0; j < 3; j++)                if (A[Ra][Ca] ==B[Rb][Cb])  printf( "They are the Same "\n)         else printf("They are not the same"\n)         return 1;    } return 0; }```
• 05-07-2009
quzah
You want to swap out the "Ra" / "Rb" and "Ca" / "Cb" with your loop counters. Also, if at any time while you are looping, the values are not equal, you can stop looking, and just return at that point, as I mentioned earlier.

Quzah.