I need to create a right triangle starting on the right working left.
Ex. (–’s are spaces)
––––X
–––XX
––XXX
–XXXX
XXXXX
A number (and the character; ex X) will be give before hand in runner. Which the code I was given. I need code to make triangle. For example if the number was 5 each line would add up to 5 characters counting from one X with 4 spaces. Then there would be 5 rows last would be all X’s.
Update:
My code prints out
––––X
–––X
––X
–X
X
(–’s spaces, no spaces after character)
Okay, let’s start with the number 5. The best bet is to simply think about what has to be output on each line and then loop over the lines doing that.
With that number, you have to output 5 lines as follows (I’ll use
.for spaces since it’s easier to discern adjacent ones):Look at each line as follows:
x.x‘s.x‘s.x‘s.x‘s.I sense a pattern here ((4,1), (3,2), (2,3), (1,4), (0,5)) – the first number starts at
n-1(4 in this case) and decreases to 0. The second number starts at 1 and increases ton(5 in this case).In pseudo-code (which is all you get from me for homeworky-type questions), it looks something like:
Your job is to then convert that into real code.