Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-02-2003, 02:52 PM   #1
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
Question filling a matrix in C

I'm having a problem trying to fill a 6x6 matrix in C

Filling it like this is a piece of cake:
Code:
 0   1   1   1   1   1
-1   0   1   1   1   1
-1  -1   0   1   1   1
-1  -1  -1   0   1   1
-1  -1  -1  -1   0   1
-1  -1  -1  -1  -1   0
But I'm having a real hard time trying to fill it like this without having to define almost every single cell:
Code:
1   1   1   1   1   0
1   1   1   1   0  -1
1   1   1   0  -1  -1
1   1   0  -1  -1  -1
1   0  -1  -1  -1  -1
0  -1  -1  -1  -1  -1
Is there a way to invert the matrix from the "piece of cake" one?

Here's what I have so far, such as it is.
Attached Files
File Type: txt ghp7.txt (1.3 KB, 72 views)
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
Force Flow is offline   Reply With Quote
Old 11-02-2003, 05:53 PM   #2
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
Updated:

I got the diagonal line. Now I just need to figure out how to fill 2 sides. I'm puzzled in this respect.
Attached Files
File Type: txt ghp7.txt (1.1 KB, 105 views)
Force Flow is offline   Reply With Quote
Old 11-02-2003, 06:26 PM   #3
Member (12 bit)
 
Paul Victorey's Avatar
 
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
Re: filling a matrix in C

Well, let's look at a for loop:

Code:
for (int i = 0; i < rows; i++){
  for (int j = 0; j < cols; j++){
  }
}
and let's put the values of i and j by the array:
Code:
 | 0   1   2   3   4   5  = j
   -   -   -   -   -   -
0| 1   1   1   1   1   0
1| 1   1   1   1   0  -1
2| 1   1   1   0  -1  -1
3| 1   1   0  -1  -1  -1
4| 1   0  -1  -1  -1  -1
5| 0  -1  -1  -1  -1  -1
=
i
Now, what condition do we have a 1? If (5-j) > i
We have a 0 when (5 - j) == i
And a -1 when (5 - j) < i
__________________
Paul M. Victorey
------------------
I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk.
Paul Victorey is offline   Reply With Quote
Old 11-02-2003, 07:06 PM   #4
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
Great! It worked! Thanks a million, Paul Victorey It was driving me up the wall
Force Flow is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:08 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2