“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.
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);
}
}
Comments
Leave a comment