Advertisement
aggressiveviking

10.RectangleWithStars

Mar 5th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _10.RectangleWithStars
  4. {
  5.     class RectangleWithStars
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int colsCnt = n * 2;
  11.             int rowsCnt;
  12.  
  13.             if (n % 2 == 0)
  14.             {
  15.                 rowsCnt = n + 1;
  16.             }
  17.             else
  18.             {
  19.                 rowsCnt = n + 2;
  20.             }
  21.  
  22.             for (int row = 0; row < rowsCnt; row++)
  23.             {
  24.                 for (int col = 0; col < colsCnt; col++)
  25.                 {
  26.                     if (row == 0 || row == rowsCnt - 1)
  27.                     {
  28.                         Console.Write("%");
  29.                     }
  30.                     else if (col == 0 || col == colsCnt - 1)
  31.                     {
  32.                         Console.Write("%");
  33.                     }
  34.                     else if (row == rowsCnt / 2 && (col == colsCnt / 2 || col == (colsCnt - 1) / 2))
  35.                     {
  36.                         Console.Write("*");
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.Write(" ");
  41.                     }
  42.                    
  43.                 }
  44.                 Console.WriteLine();
  45.             }
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement