Re: Printing Patterns using for loops
- From: "Vladimir S. Oka" <novine@xxxxxxxxxxxxxxx>
- Date: 28 Feb 2006 07:38:54 -0800
priyam.trivedi@xxxxxxxxx wrote:
I saw this in one article but I cannot understand why the coder has
used z--. I did it without z-- and it still works the same.
There's no `z--` in the code you posted, but I think I still get what
you mean (Temp--).
<snip... the pattern>
void PrintPatternThree (int PatternSize)
{
int Row = 0;
int Col = 0;
int Temp = 0; // used to hold the new value of PatternSize for
evaluating
These initialisations are superflous and hence confusing, as you
immediatelly re-initialise these variables with different values.
Temp = PatternSize;
This actually does not get used at all (apart from decrementing it).
for (Row = 1; Row <= PatternSize; Row++)
{
for (Col = 1; Col <=PatternSize; Col++)
{
if (Row <= Col)
printf ( "$" );
else
printf ( "%d", PatternSize);
} // end Col
Temp--;
printf ( "\n" );
} // end Row
Don't use `//` for comments, at least in newsgroups, as it may foul the
quoting.
return;
} /* end PrintPatternFour()
$$$$$
$$$$5
$$$55
$$555
$5555 */
I guess `Temp` is a leftover from a different way of implementing this.
E.g. `Temp` could be used instead of `Row` in a `while` loop.
int Temp = PatternSize;
while (Temp)
{
/* do stuff with Col; use Temp instead of Row (not a straight
replacement!) */;
--Temp;
}
OTH, you could also use PatternSize. C passes arguments by value, so
you wouldn't mess whatever is passed in the function call.
--
BR, Vladimir
.
- References:
- Printing Patterns using for loops
- From: priyam.trivedi@xxxxxxxxx
- Printing Patterns using for loops
- Prev by Date: Re: Hellp with type promotion
- Next by Date: Re: malloc behavior on failure
- Previous by thread: Printing Patterns using for loops
- Next by thread: Make fast money in the mail order buisness!
- Index(es):
Relevant Pages
|