Answered step by step
Verified Expert Solution
Link Copied!

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:image text in transcribed

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 text

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

10. What is meant by a feed rate?

Answered: 1 week ago