Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Trapezoid
- {
- static void Main()
- {
- //Write a program that prints on the console the border of a trapezoid by given number N.
- //The width of the top side of the trapezoid must be exactly N.
- //The width of the bottom side of the trapezoid must be exactly 2 * N.
- //The height of the trapezoid must be exactly N + 1.
- //Also the top right and the bottom right angle of the trapezoid must be equal to 90 degrees.
- //On the only line in the console you are given an integer number N, showing the width of the smallest trapezoid side.
- int smallSide = byte.Parse(Console.ReadLine());
- int starPosition = smallSide;
- for (int row = 1; row <= (smallSide + 1); row++)
- {
- for (int column = 1; column <= (2 * smallSide); column++)
- {
- //if we are at the first row
- if (row == 1)
- {
- if (column <= smallSide)
- {
- Console.Write(".");
- }
- else if (column > smallSide)
- {
- Console.Write("*");
- }
- continue;
- }
- //If we are at the last row
- if (row == (smallSide + 1))
- {
- Console.Write("*");
- continue;
- }
- //If it is the middle rows
- if (starPosition == column)
- {
- Console.Write("*");
- starPosition--;
- }
- else if (column == (2*smallSide))
- {
- Console.Write("*");
- }
- else
- Console.Write(".");
- }
- Console.WriteLine("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment