Interior elements and border elements of a Matrix

adding the interior only elements and the border only elements

Page 1 of 1

2 Replies - 8526 Views - Last Post: 23 October 2008 - 10:14 AM Rate Topic: -----

#1 wakemalibu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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.
For example, if you had

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   User is offline

  • D.I.C Regular
  • member icon

Reputation: 46
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 wakemalibu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1