Advertisement
sashomaga

Trapezoid

Dec 26th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. //Write a program that prints on the console the border of a trapezoid by given number N.
  3. //The width of the top side of the trapezoid must be exactly N.
  4. //The width of the bottom side of the trapezoid must be exactly 2 * N.
  5. //The height of the trapezoid must be exactly N + 1.
  6. //Also the top right and the bottom right angle of the trapezoid must be equal to 90 degrees.
  7.  
  8. class Program
  9. {
  10.     static void Main()
  11.     {
  12.         int n = int.Parse(Console.ReadLine());
  13.         for (int j = 0; j < n+1; j++)
  14.         {
  15.             for (int i = 0; i < 2 * n; i++)
  16.             {
  17.                 if (j == 0) //first row
  18.                 {
  19.                     if (i + n >= 2 * n)
  20.                     {
  21.                         Console.Write("*");
  22.                     }
  23.                     else
  24.                     {
  25.                         Console.Write(".");
  26.                     }
  27.                 }
  28.                 if (j == n) //last row
  29.                 {
  30.                     Console.Write("*");
  31.                 }
  32.                 else if(j > 0) //mid rows
  33.                 {
  34.                     if (i == n - j || i == 2 * n - 1)
  35.                     {
  36.                         Console.Write("*");
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.Write(".");
  41.                     }
  42.                    
  43.                 }
  44.             }
  45.             Console.WriteLine();
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement