kvadrat4o

diamond

Mar 19th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 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.             //Console.WriteLine("Enter a number here: ");
  14.             int n = int.Parse(Console.ReadLine());
  15.             int countDashes = 0;
  16.             if (n%2==1)
  17.             {
  18.                 //first line
  19.                 Console.WriteLine("{0}{1}{2}", new string('-', n / 2), "*", new string('-', n / 2));
  20.                 countDashes++;
  21.             }
  22.             //middle part
  23.             for (int i = 0; i < n / 2; i++)
  24.             {
  25.                     Console.WriteLine("{0}{1}{2}{3}{4}",new string('-',n/2-1-i)+"*"+new string('-',countDashes+2*i)+"*"+new string('-',n/2-1-i));
  26.             }
  27.             for (int i = 0; i < n/2-1; i++)
  28.             {
  29.                 Console.WriteLine("{0}{1}{2}{3}{4}", new string('-',1 + i) + "*" + new string('-', n-4-2*i) + "*" + new string('-',1 +i));
  30.             }
  31.             if (n%2==1)
  32.             {
  33.                 //last line
  34.                 Console.WriteLine("{0}{1}{2}", new string('-', n / 2),"*", new string('-', n / 2));
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment