Advertisement
Razhagal

Trapezoid

Mar 11th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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 Trapezoid
  8. {
  9.     class Trapezoid
  10.     {
  11.         static void Main()
  12.         {
  13.             //Input
  14.             int N = int.Parse(Console.ReadLine());
  15.             int rows = N + 1;
  16.             int cols = 2 * N;
  17.             int[,] matrix = new int[rows, cols];
  18.            
  19.             //Fill the matrix
  20.             for (int col = N; col < cols; col++)
  21.             {
  22.                 matrix[0, col] = 1;
  23.             }
  24.  
  25.             for (int row = 1; row < rows; row++)
  26.             {
  27.                 matrix[row, cols - 1] = 1;
  28.             }
  29.  
  30.             for (int col = cols - 1; col >= 0; col--)
  31.             {
  32.                 matrix[rows - 1, col] = 1;
  33.             }
  34.  
  35.             //int currentRow = 0;
  36.             int currentCol = 0;
  37.             for (int row = rows - 1; row >= 0; row--)
  38.             {
  39.                 matrix[row, currentCol] = 1;
  40.                 currentCol++;
  41.             }
  42.  
  43.             //Output
  44.             for (int row = 0; row < rows; row++)
  45.             {
  46.                 for (int col = 0; col < cols; col++)
  47.                 {
  48.                     if (matrix[row, col] == 0)
  49.                     {
  50.                         Console.Write(".");
  51.                     }
  52.                     else if (matrix[row, col] == 1)
  53.                     {
  54.                         Console.Write("*");
  55.                     }
  56.                 }
  57.                 Console.WriteLine();
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement