Advertisement
simonradev

Diamond

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