sylviapsh

Trapezoid

Dec 26th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. class Trapezoid
  3. {
  4.   static void Main()
  5.   {
  6.     //Write a program that prints on the console the border of a trapezoid by given number N.
  7.     //The width of the top side of the trapezoid must be exactly N.
  8.     //The width of the bottom side of the trapezoid must be exactly 2 * N.
  9.     //The height of the trapezoid must be exactly N + 1.
  10.     //Also the top right and the bottom right angle of the trapezoid must be equal to 90 degrees.
  11.     //On the only line in the console you are given an integer number N, showing the width of the smallest trapezoid side.
  12.  
  13.     int smallSide = byte.Parse(Console.ReadLine());
  14.     int starPosition = smallSide;
  15.  
  16.     for (int row = 1; row <= (smallSide + 1); row++)
  17.     {
  18.       for (int column = 1; column <= (2 * smallSide); column++)
  19.       {
  20.         //if we are at the first row
  21.         if (row == 1)
  22.         {
  23.           if (column <= smallSide)
  24.           {
  25.             Console.Write(".");
  26.           }
  27.           else if (column > smallSide)
  28.           {
  29.             Console.Write("*");
  30.           }
  31.           continue;
  32.         }
  33.      
  34.         //If we are at the last row
  35.         if (row == (smallSide + 1))
  36.         {
  37.           Console.Write("*");
  38.           continue;
  39.         }
  40.  
  41.         //If it is the middle rows
  42.         if (starPosition == column)
  43.         {
  44.           Console.Write("*");
  45.           starPosition--;
  46.         }
  47.         else if (column == (2*smallSide))
  48.         {
  49.           Console.Write("*");
  50.         }
  51.         else
  52.           Console.Write(".");
  53.       }
  54.       Console.WriteLine("");
  55.     }
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment