Advertisement
VickyFilly

C#Basics_Diamond

Mar 17th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _10_Diamond
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int size = int.Parse(Console.ReadLine());
  10.  
  11.             int stars = size % 2 == 0 ? 2 : 1;
  12.             int topspace = (size - stars) / 2;
  13.  
  14.             string topstars = new string('*', stars);
  15.             string topspaces = new string('-', topspace);
  16.  
  17.             Console.WriteLine("{0}{1}{0}", topspaces, topstars, topspaces);
  18.  
  19.  
  20.             int secondrowdash = stars;
  21.  
  22.             int secondrowsides = (size - 2 - secondrowdash) / 2;
  23.  
  24.             int rows = (size - 1) / 2;
  25.  
  26.             for (int a = 0; a < rows; a++)
  27.             {
  28.                 string secondrowdmidashes = new string('-', secondrowdash);
  29.                 string secondrowsidedash = new string('-', secondrowsides);
  30.                 Console.WriteLine("{0}*{1}*{0}", secondrowsidedash, secondrowdmidashes);
  31.                 secondrowsides--;
  32.                 secondrowdash+=2;
  33.             }
  34.  
  35.             secondrowsides+=2;
  36.             secondrowdash -= 4;
  37.             for (int b = 0; b < rows - 1; b++)
  38.             {
  39.  
  40.                 string secondrowdmidashes = new string('-', secondrowdash);
  41.                 string secondrowsidedash = new string('-', secondrowsides);
  42.                 Console.WriteLine("{0}*{1}*{0}", secondrowsidedash, secondrowdmidashes);
  43.                 secondrowsides++;
  44.                 secondrowdash -= 2;
  45.             }
  46.  
  47.  
  48.             if (size > 2) { Console.WriteLine("{0}{1}{0}", topspaces, topstars, topspaces); }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement