C simple Matrices

This is a discussion on C simple Matrices within the C Programming forums, part of the General Programming Boards category; i can't figure out the function part, although i tried i don't know if it makes sense, since I'm a ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    Question 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;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    is it some like this?

    Quote Originally Posted by quzah View Post
    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;
    }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 06:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21