I've been given a homework assignment that asks to print an equilateral triangle with '*' as the frame and inside the triangle a string of fixed number of '$' and spaces is supposed to run.
example: Enter height: 9 Enter number of $: 5 Enter number of spaces: 2
I am lost here, help?
Let's see over what logic it works. You will find code at last.
1st.
How to create left-side star pattern like this :First thing is how many spaces on the left of each star is equal to
TOTAL_HEIGHT_OF_PATTERN - CURRENT_HEIGHT_STATUS
. for given example let's take2nd-line
so:2nd.
How to create `$` and `space` pattern like this in between: (BOTTOM PATTERN IS ONLY FOR VISUALIZATION)How many spaces at given height, for above system it is found.
spaces:0 for height @ 1, 2, 3
spaces:1 for height @ 4, 5, 6
spaces:2 for height @ 7, 8
Instead of completely using loop let's divide them in procedural code. For making particular
enclose-string
we can usemake_str function
who logic revolves around the remaining number of$
CODE :
OUTPUT :