Answer to Question #332183 in C# for Macky

Question #332183

“Our state of the art algorithm allows you to simply input the width and height of your skyscraper, and using a specially trained machine learning model, it would automatically generate a “star” (*) image of the entire structure. Specifically, the foundation of the building would always be width + 2 stars wide, while the top of the tower contains 1 star if the width is an odd number, or 2 stars if the width is an even number. Are you ready to see how it works?”


) Apart from the base and the top level of the tower, every level starts and ends with a white space(" ").


The first line will contain a message prompt to width of the skyscraper.


The second line will contain a message prompt to height of the skyscraper.


The succeeding lines will contain the skyscraper pattern.

1
Expert's answer
2022-04-22T13:30:44-0400
using System;
using System.Linq;
using System.Text;


class Program
{
    static void Main()
    {
        Console.Write("Enter width of the skyscraper: ");
        int width = int.Parse(Console.ReadLine());


        Console.Write("Enter height of the skyscraper: ");
        int height = int.Parse(Console.ReadLine());


        string[] array = new string[height];
        int skipped = 0;
        for (int i = array.Length - 1; i >= 0; i--)
        {
            array[i] = new string(' ', skipped / 2) + new string('*', width) + new string(' ', skipped / 2);
            if (width > 2)
            {
                skipped += 2;
                width -= 2;
            }
        }


        foreach (var item in array)
            Console.WriteLine(item);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS