two-dimensional arrays

This is a discussion on two-dimensional arrays within the C++ Programming forums, part of the General Programming Boards category; We had to write three two dimensional arrays A[10][10],B[10][10],C[10][10]. Cin numbers into A and B and then add them together ...

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

    two-dimensional arrays

    We had to write three two dimensional arrays A[10][10],B[10][10],C[10][10]. Cin numbers into A and B and then add them together and store them in C. using the numbers 0-9,now we have to tell how many numbers in A are 1, how many are 2, and so on. In B we have to show how many 1,3,5,7,9 were used. and display the output. I finally got the numbers input and added but how to I figure how many of each number was used?
    Thanks for any help.
    jblea

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You could use a double for loop to transverse the colums and rows.

    Code:
    int one = 0, two = 0, three = 0; // etc.....
    int data;
    
    for( int row = 0; row < 10; row++ )
    {
         for( int col = 0; col < 10; col++ )
         {
              data = A[col][row];
              switch( data )
              {
                     case 1:   // If it's a 1, then increment counter
                          one++;
                          break;
                              . 
                              .
                              .
               }         
          }
    }
    Hope this helps If not, IM me or post back

  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    if you didn't like the switch, try a bunch of if's:

    Code:
    //....
    data = A[col][row];
    if (data==1)
    one++;
    //.....

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    5
    Thanks guys I'll work on finishing it today.

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, 03:49 PM
  2. Dynamic two dimensional arrays
    By ThWolf in forum C++ Programming
    Replies: 14
    Last Post: 08-30-2006, 02:28 PM
  3. dimensional arrays
    By ZakkWylde969 in forum C++ Programming
    Replies: 3
    Last Post: 08-04-2003, 04:49 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, 11:53 AM

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