-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Could anyone over here, write a program in C using only for loop to
print the following output
*
***
*****
*******
*********
***********
I tried but could only get one side of the triangle...
Quick reply is appreciated. Thanks,
This is not a C question, and thus is off topic here.
But here's a hint
Assuming that the top line of the triangle is #1, and the next line down is
line #2, try to relate the number of stars in a line to the line number. Also,
try to relate the number of spaces before the first star to the line number.
You should be able to come up with two formula, one for stars and one for
spaces, that vary properly with line number.
Now, re-read the information on printf() format codes, paying particular
attention to the "field width" and "precision" specifiers. See if there is a
way to use the two formula from above to regulate your printf() output.
You should be able to reconstruct the triangle with /one/ for() loop and /one/
printf(), within certain limits of triangle size.
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (
http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)
iD8DBQFDYstkagVFX4UWr64RAv/fAKDgEjxdeDH5642W/MX0ct6Fz8j8dACg7Qt0
BxFRlt/IzSFt+qoKGC4Oh2g=
=+wmS
-----END PGP SIGNATURE-----