![]() |
|
#1
|
|||
|
|||
Nested For-loops problemI am attempting to create a code where the user inputs an equal number of rows and clumns and the output is the identity matrix. For example, with 3 rows and 3 columns, the output would look like this:
100 010 001 I am required to use nested for-loops. Here is what I thought would work, but won't: CPP / C++ / C Code:
Any help I could get would be much appreciated. Thank you! |
|
#2
|
||||
|
||||
Re: Nested For-loops problemHi,
Just change CPP / C++ / C Code:
to this: CPP / C++ / C Code:
The double equals sign == is the C notation for ``is equal to''. This symbol is used to distinguish the equality test from the single = that C uses for assignment. A word of caution: The result is usually a legal expression, so you will get no warning. Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: Nested For-loops problemThank you so much, Paramesh! I am so new at this and I never realize when my silly mistakes are there.
|
|
#4
|
||||
|
||||
Re: Nested For-loops problemYou are Welcome.
and Read this $ 20 Million Bug story: Quote:
Cheers, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. Last edited by Paramesh : 14-Oct-2005 at 10:59.
|
|
#5
|
|||
|
|||
Re: Nested For-loops problemWhat you have works, but just a couple notes on possibly making it easier to read and easier to program.
instead of useing CPP / C++ / C Code:
try this... it does the same thing you can replace -------------------------------- i < (rows + 1) with i <= rows -------------------------------- j < (columns + 1) with j <= columns -------------------------------- Also cpp as a build in operator for adding or subtracting 1 from a number, for example. -------------------------------- i = i + 1 is the same as i++ -------------------------------- i = i - 1 is the same as i-- -------------------------------- also a couple more handy operators are += and -= there are also *= and /= operators that work in the same way. -------------------------------- i = i + n is the same as i += n -------------------------------- i = i - n is the same as i -= n -------------------------------- CPP / C++ / C Code:
Not sure if u will ever check back on this post but those are just a couple of operators in c++ that you might find handy. They make my life much easier, hope it helps you too. __________________
There are 10 kinds of people in this world. Those who speak binary and those who dont. |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 12:31 |
| Runtime Problem involving "printf" in C Program | supamakia | C Programming Language | 2 | 09-Oct-2005 10:09 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
| Help with nested for loops...please. sorry newbie | keperry | C++ Forum | 14 | 16-Oct-2004 11:25 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 07:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The