Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a * based Christmas tree that looks like the following: * *** ***** ******* ********** * Use a loop to algoritmically create the top
- Create a * based Christmas tree that looks like the following:
- *
- ***
- *****
- *******
- **********
- *
- Use a loop to algoritmically create the top five lines of the tree
- The first line has 4 spaces followed by 1 *
- The next line has 3 spaces followed by 3 *
- The next line has 2 spaces followed by 5 *
- The next line has 1 spaces followed by 7 *
- The last line has 0 spaces followed by 9 *
- Store each output line on the tree in an Array
- Finally use one more array to output the contents of your Array
My code is as follows:
var arr = [String]()
for i in 1...5 {
for _ in 1...2*i-1 {
arr.append("*")
}
arr.append(" ")
}
for i in arr{
print(i, terminator: "")
}
it outputs the image above. I need to make the output look like a tree. How do I fix this?
Transcribed image textStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started