Matrix Arrays

This is a discussion on Matrix Arrays within the C Programming forums, part of the General Programming Boards category; I need to write a program which uses a pointer to access the elemnts of an array A and an ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    19

    Matrix Arrays

    I need to write a program which uses a pointer to access the elemnts of an array A and an array B (which is the transpose of A) this is what i have so far, but how would i set up the pointer to print an element from each of these matrices?
    Thanx


    Code:
    #include <stdlib.h>
    #include <math.h>
    #include <stdio.h>
    #include <string.h>
    
    main()
    	{
    		long int A[3][4] = 	{1, 2, 3, 4,
    				    	5, 6, 7, 8,
    				   	9, 10, 11, 12};
    		long int B[4][3] =	{1, 5, 9,
    					 2, 6, 10,
    					 3, 7, 11,
    					 4, 8, 12};
    		printf ("%i %i %i\n", B[0][0], B[0][1], B[0][2]);
    		printf ("%i %i %i\n", B[1][0], B[1][1], B[1][2]);
    		printf ("%i %i %i\n", B[2][0], B[2][1], B[2][2]);
    		printf ("%i %i %i\n", B[3][0], B[3][1], B[3][2]);
    
    		long int *ptr
    	}

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Code:
    for(ptr = A;ptr - A < 3*4;ptr++)
      printf("%i\n", *ptr);
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    19
    No this just prints out every value from the matrix. I need the pointer to print out the elements A[1][3] and B[1][0]. Is this possible?

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Code:
    ptr = &A[1][3];
    printf("%i\n", *ptr);
    Repeat for B[1][0].
    Is this possible?
    Why would your instructor give you an assignment that was impossible?

    P.S. Next time state your needs in your original post.
    Last edited by itsme86; 12-12-2005 at 12:22 PM.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    19
    yes but does this not mean i will hve to use two separate pointers?

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    19
    ok i get it now, thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 04:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 07:31 PM
  4. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-13-2004, 11:19 PM

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