# Simple triangle printer (kinda)

• 08-30-2011, 03:04 AM
5myl
Simple triangle printer (kinda)
So for my computer class, my instructor gave me a challenge problem since i was doe with the rest of the work, its the beginning of the year so its kind of simple... but i can't wrap my mind around it. the problem is To create a program that prints out a triangle based on 'n'... for example:

if n = 3,

it would print out:

___*
__**
_***

(the underscore would be the spaces since it won't show up)
anyways, i know it would have to do something with a for loop, but i don't know how to account for the spaces before the stars.

If somebody could tell me a way to go about it or how to figure it out, i would greatly appreciate it.
• 08-30-2011, 03:14 AM
Junky
You need to grab a pen and some paper. Draw various n sized triangles and count how many spaces appear before each *. If you do this enough you should see a pattern emerging. Given n then you can calculate what the initial number of spaces will be.
• 08-30-2011, 03:29 AM
5myl
Thanks, after reading your post i thought of something else completely and suddenly i figured it out... :)
but the counting of spaces helped as well