# Interior elements and border elements of a Matrix

Page 1 of 1

## 2 Replies - 9213 Views - Last Post: 23 October 2008 - 10:14 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=68654&amp;s=76e38e47c8ec6e02bc9e4cd9e61f60fd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 wakemalibu

Reputation: 1
• Posts: 24
• Joined: 30-September 08

# Interior elements and border elements of a Matrix

Posted 22 October 2008 - 02:56 PM

hey Im having trouble with my loops on how to add the interior elements of a matrix together if there are any and the border only elements of a matrix together.

XXXXX
XXXXX
XXXXX

the underlined items would be ur interior elements that you need to add together and the rest of the elements that arent underlined are your border items. The border items must be added together seperately. So you get two different Sums. interior_Sum and border_Sum.
This is what i have so far. Basicly I know that its my loops so I just need help on how to change them to only add the certain elements described above together into their particular sum.

for (int i=0; i <= n-1; i++)

{

for (int j=0; j <= n-1; j++)

{

border_Sum = border_Sum + x[i][j];

}

}

This is for border. below is for interior if their is an interior of the matrix

for (int i=0; i <= n-1; i++)

{

for ( int j=0; j <=n-1; j++)

{

interior_Sum = interior_Sum + x[i][j];

}

}

Remember we are working with 2 dimensional matrixs where rows and columns are a factor. The loops need ot be able to adjust to a number of different matrixes that the user defines. not just the one i posted above. The matrixes only go up to 10 * 10. Thanks

This post has been edited by wakemalibu: 22 October 2008 - 02:58 PM

Is This A Good Question/Topic? 0

## Replies To: Interior elements and border elements of a Matrix

### #2 salindor

• D.I.C Regular

Reputation: 46
• Posts: 304
• Joined: 10-November 06

## Re: Interior elements and border elements of a Matrix

Posted 22 October 2008 - 05:42 PM

I don't want to write the program for you; but you are close. Instead of thinking you need two loops; think about using an if statement instead.

I am going to have to remember this problem statement next time I teach loops; I like it.

Salindor

### #3 wakemalibu

Reputation: 1
• Posts: 24
• Joined: 30-September 08

## Re: Interior elements and border elements of a Matrix

Posted 23 October 2008 - 10:14 AM

okay an if statement such as one that talks about x[i][j] and compares?