# two-dimensional arrays

• 04-02-2002
jblea
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
• 04-02-2002
MrWizard
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
• 04-02-2002
blight2c
if you didn't like the switch, try a bunch of if's:

Code:

```//.... data = A[col][row]; if (data==1) one++; //.....```
• 04-03-2002
jblea
Thanks guys I'll work on finishing it today.