Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp2
- {
- public class Program
- {
- public static void Main()
- {
- int length = int.Parse(Console.ReadLine());
- string star = "* ";
- string whiteSpace = " ";
- PrintTriangleUp(length, star, whiteSpace);
- PrintTriangleDown(length, star, whiteSpace);
- }
- public static void PrintTriangleUp(int length, string star, string whiteSpace)
- {
- int whiteSpaceLength = length - 1;
- for (int i = 1; i <= length; i++)
- {
- PrintWhiteSpace(whiteSpaceLength, whiteSpace);
- whiteSpaceLength -= 1;
- PrintStars(i, star);
- Console.WriteLine();
- }
- }
- public static void PrintTriangleDown(int length, string star, string whiteSpace)
- {
- length -= 1;
- int whiteSpaceLength = 1;
- for (int i = length; i >= 0; i--)
- {
- PrintWhiteSpace(whiteSpaceLength, whiteSpace);
- whiteSpaceLength += 1;
- PrintStars(i, star);
- Console.WriteLine();
- }
- }
- public static void PrintWhiteSpace(int whiteSpaceLength, string whiteSpace)
- {
- for (int i = 0; i < whiteSpaceLength; i++)
- {
- Console.Write(whiteSpace);
- }
- }
- public static void PrintStars(int starsLength, string star)
- {
- for (int i = 0; i < starsLength; i++)
- {
- Console.Write(star);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment