Thread: populating two dimensional arrays

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    5

    populating two dimensional arrays


    I have an assignment that requires me to populate a two dimensioanl array and then use it to prepare a summary based on that array.
    Ex. three stores each have three products, have the user input the total of each product for each store and then have the program list that information.

    As far as I have gotten is this code for populating the array:

    int iar[3][4]
    for (rown=0;rown<3;j++)
    for(coln=0;coln<4;k++)
    printf("enter element ar[%d][%d]",rown, coln);
    scanf("%d",&iar[rown][coln]);

    If i could just get somebody to show me a complete program that populates a two dimensional array and then lists that information, I could finish the rest of the program.

    Thanks to anybody that can help

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int x, y, array[3][4];
    
    for( y = 0; y < 4; y++ )for( x = 0; x < 3; x++ )
    {
        printf( "Enter a value for array[%d][%d]: ", x, y );
        scanf( "%d", array[x][y] );
    }
    
    for( y = 0; y < 4; y++ )for( x = 0; x < 3; x++ )
    {
        printf( "The value of array[%d][%d]: is %d.\n", x, y, array[x][y] );
    }
    Enjoy.

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

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    for( y = 0; y < 4; y++ )for( x = 0; x < 3; x++ )
    {
        printf( "Enter a value for array[%d][%d]: ", x, y );
        scanf( "%d", array[x][y] );
    }
    That's an interesting implementation of nested loops. Kind of scary too.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  2. Dynamic two dimensional arrays
    By ThWolf in forum C++ Programming
    Replies: 14
    Last Post: 08-30-2006, 02:28 PM
  3. passing two dimensional arrays
    By Nova_Collision in forum C++ Programming
    Replies: 3
    Last Post: 02-04-2003, 01:47 PM
  4. two dimensional arrays
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 05-01-2002, 08:12 PM
  5. Two dimensional arrays
    By Jax in forum C Programming
    Replies: 1
    Last Post: 11-07-2001, 12:53 PM