Thread: multidimensonal matrix representing in a single array

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    6

    multidimensonal matrix representing in a single array

    To store a multi dimensional matrix in a single array. User will enter the index of the element and it will give the element to the user from the array.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Multiply each dimension together to get the total number of elements. Allocate one block that size with something like malloc.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    6
    Quote Originally Posted by quzah View Post
    Multiply each dimension together to get the total number of elements. Allocate one block that size with something like malloc.


    Quzah.
    can u please give me the codes?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Can, yes. Will, no. We're not here to do everything for you. Make an effort.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    6
    I tried many a hundred times.......but something wrong in me.........please give me...........its very important.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's not important at all to me. Show us your attempt, or look elsewhere.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    6
    my problem is in runnig the loop......i have allocated the memory space how much it need.........but it giving something wrong in the loop..........so i need some help in running the loop.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Let's try this again.

    Show.
    Us.
    Your.
    Attempt.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Mar 2010
    Posts
    6
    ok i will show u after a little while how i have done.......

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Abh, think of a very small and simple example:

    Say your array was array[2][2]. So it would look like:

    Code:
    1 2
    3 4
    if it had 1,2,3,4 as it's values, and you printed it out by it's rows. Now, if I printed it out all in one line, it would look like: 1 2 3 4. So clearly, it has 2 x 2 or 4 elements in it, and would be just the same as a 1 dimension array with 4 elements: 1 2 3 4.

    That same idea, works with arrays of any size, and any number of dimensions.

  11. #11
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Now I can go to bed with a smile. Reading this was a fun!
    The keyboard is the standard device used to cause computer errors!

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. Help with matrix transpose
    By sass208 in forum C Programming
    Replies: 6
    Last Post: 12-09-2006, 02:02 AM
  3. Representing a Large Integer with an Array
    By random_accident in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2005, 12:23 PM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM