“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.
For example:
Output:
Enter·width·of·skyscraper:·5
Enter·height·of·skyscraper:·10
*
*****
*****
*****
*****
*****
*****
*****
*****
*******
using System;
class Program {
public static void Main (string[] args) {
//
Console.Write("Enter width of the skyscraper: ");
int w = Convert.ToInt32(Console.ReadLine());//Convert
Console.Write("Enter height of the skyscraper: ");
int h = Convert.ToInt32(Console.ReadLine());
w+=2;//Because foundation +2 star*
string[] cur = new string[h];
int skipped = 0;
for (int i = cur.Length - 1; i >= 0; i--)
{
//create string for each line
cur[i] = new string(' ', skipped / 2) + new string('*', w) + new string(' ', skipped / 2);
if (w > 2)
{
skipped += 2;
w -= 2;
}
}
foreach (var skyscrap in cur)
Console.WriteLine(skyscrap);
}
}
Comments
Leave a comment