stkirov

Problem 3 – Trapezoid

Oct 26th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. //Write a program that prints on the console the border of a trapezoid by given number N.
  2. //The width of the top side of the trapezoid must be exactly N.
  3. //The width of the bottom side of the trapezoid must be exactly 2 * N.
  4. //The height of the trapezoid must be exactly N + 1.
  5. //Also the top right and the bottom right angle of the trapezoid must be equal to 90 degrees.
  6. //See the examples bellow.
  7. //Input
  8. //The input data is being read from the console.
  9. //On the only line in the console you are given an integer number N, showing the width of the smallest trapezoid side.
  10. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  11. //Output
  12. //The output data must be printed on the console.
  13. //You must write the border of the described trapezoid on the console.
  14. //Use the symbol “*” (asterisk) to mark the border of the trapezoid.
  15. //Use the symbol “.” (dot) to illustrate the empty spaces outside and inside the trapezoid.
  16. //Constraints
  17. //•   The number N is a positive integer between 3 and 39, inclusive.
  18. //•   Allowed working time for your program: 0.25 seconds.
  19. //•   Allowed memory: 16 MB.
  20.  
  21.  
  22. using System;
  23.  
  24. class Program
  25. {
  26.     static void Main()
  27.     {
  28.         int n = int.Parse(Console.ReadLine());
  29.         Console.WriteLine("{0}{1}", new string('.', n), new string('*', n));
  30.         for (int i = 1; i < n; i++)
  31.         {
  32.             Console.Write("{0}", new string('.', n - i));
  33.             Console.Write('*');
  34.             Console.Write("{0}", new string('.', (n + i)-2));
  35.             Console.Write('*');
  36.             Console.WriteLine();
  37.         }
  38.         Console.WriteLine("{0}", new string('*', n*2));
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment