### Multidimensional Arrays

I would like to store all the even numbers from 1 to 100 in an multidimensional array and then find the average of them. This is what i have.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 #include using namespace std; double averagef (double x[]);//prototyping function int main() { double even [8][5];//array to store even numbers for(int rows =0;rows<8;rows++)//loop for the rows { for (int column = 0;column<5;column++)//loop for the column { for(int i = 0;i<100;i++)//loop to count to 100 { if ( i % 2== 0 )//if statement to check if the number is even { even [i][i] = i;//store the number if even }//end if }//end counting loop }//end of column loop }//end rows loop cout<<"The average of the 40 even numbers is:"<

Let's work on the logic first. For example:

 12345678910111213141516171819 int even[8][5]; int row = 0; int column = 0; for(int nCount = 1; nCount < 101; nCount++) { if(nCount %2 == 0) // test for even. { even[row][column] = nCount; // set the position in the array. // increment the positions in the array. column++; if(column > 4) { column=0; row++; if(row > 7) break; // array bounds check.. } }
ok i'll try that thanks
Topic archived. No new replies allowed.