using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
//The size of the triangle should not be larger than 10.
int size = -1;
Console.Write("Enter the size of the triangle: ");
if (!int.TryParse(Console.ReadLine(), out size) || size > 10)
{
size = 3;
}
Console.Write("Enter the character of the triangle: ");
string character = Console.ReadLine();
if (character.Length > 1 || Char.IsDigit(character[0]))
{
character = "*";
}
for (int i = 1; i <= size; i++)
{
for (int j = 0; j < i; j++)
{
Console.Write(character);
}
Console.WriteLine();
}
for (int i = size-1; i >= 1; i--)
{
for (int j = 0; j < i; j++)
{
Console.Write(character);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Comments
Leave a comment