WindFell

Diamond

Feb 10th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Diamond
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             int stars = 1;
  16.             int rows = n;
  17.  
  18.             if (n % 2 == 0)
  19.             {
  20.                 stars = 2;
  21.                 rows = n - 1;
  22.             }
  23.             int sides = (n - stars) / 2;
  24.             int middle = stars - 2;
  25.             string row;
  26.  
  27.             for (int i = 1; i <= rows / 2 + 1; i++)
  28.             {
  29.                 if (i == 1)
  30.                 {
  31.                     row = $"{new string('-', sides)}{new string('*', stars)}{new string('-', sides)}";
  32.                 }
  33.                 else
  34.                 {
  35.                     row = $"{new string('-', sides)}*{new string('-', middle)}*{new string('-', sides)}";
  36.                 }
  37.                 sides--;
  38.                 middle += 2;
  39.                 Console.WriteLine(row);
  40.             }
  41.             sides += 2;
  42.             middle -= 4;
  43.             for (int i = 1; i <= rows / 2; i++)
  44.             {
  45.                 if (i == rows / 2)
  46.                 {
  47.                     row = $"{new string('-', sides)}{new string('*', stars)}{new string('-', sides)}";
  48.                 }
  49.                 else
  50.                 {
  51.                     row = $"{new string('-', sides)}*{new string('-', middle)}*{new string('-', sides)}";
  52.                 }
  53.                 sides++;
  54.                 middle -= 2;
  55.                 Console.WriteLine(row);
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment