2-D Arrays (Matrices)

This is a discussion on 2-D Arrays (Matrices) within the C Programming forums, part of the General Programming Boards category; I'm confused I have to creat 2 matrices and then produce a third matrxi. But here is the problem that ...

  1. #1
    Mak
    Mak is offline
    Registered User
    Join Date
    Oct 2003
    Posts
    33

    Question 2-D Arrays (Matrices)

    I'm confused

    I have to creat 2 matrices and then produce a third matrxi. But here is the problem that i have:

    Question states "third matrix whose all off diagonal entries are zero and the diagonal entries are the sum of first 2 matrices."

    Off diagonal? diagonal? I dotn get that

    1 3 5
    5 6 7
    7 9 9

    would diagonal be 1,6 and 9? and the rest off diagonal?

    and then i'm not really sure how to add them...so far i have:

    Code:
    void get_mat(int mat[][3]);
    void get_mat2(int matx[][3]);
    void add_mat(int mat1[][3], int mat2[][3], int mat3[][3]);
    void ptr_mat(int mat[][3]);
    
    main()
    {
    
    
    int matrix[3][3];
    int matrix1[3][3];
    int matrix2[3][3];
    
    get_mat(matrix);
    get_mat2(matrix1);
    
    add_mat(matrix, matrix1, matrix2);
    ptr_mat(matrix2);
    
    }
    
    void get_mat(int mat[][3])
    {
    int i, j;
    
    for(i=0; i<3; i++){
    for(j=0; j<3; j==){
    printf("Please enter Matrix 1 [%d][%d]", i,j)'
    scamf("%d", &mat[i][j]);
    		}
    	}
    }
    
    
    void get_mat(int mat2[][3])
    {
    int i, j;
    
    for(i=0; i<3; i++){
    for(j=0; j<3; j==){
    printf("Please enter Matrix 1 [%d][%d]", i,j)'
    scamf("%d", &mat2[i][j]);
    		}
    	}
    }

    thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > would diagonal be 1,6 and 9? and the rest off diagonal?
    Seems about right to me, from what I can remember.

    This indexes the diagonal
    for ( i = 0 ; i < n ; i++ ) mat[i][i] = 0;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Mak
    Mak is offline
    Registered User
    Join Date
    Oct 2003
    Posts
    33
    never mind...got it working
    Last edited by Mak; 11-27-2003 at 03:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help with Matrices and Arrays
    By dcwang3 in forum C Programming
    Replies: 7
    Last Post: 02-17-2008, 03:53 PM
  2. Adding Arrays and Matrices
    By dlf in forum C++ Programming
    Replies: 3
    Last Post: 11-30-2005, 01:36 PM
  3. Multidimensional arrays as Matrices
    By alvifarooq in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2005, 12:15 AM
  4. What are the differences between arrays and matrices?
    By incognito in forum C++ Programming
    Replies: 3
    Last Post: 03-11-2003, 12:09 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

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