c# 打印三角菱形
//打印三角菱形
Console.WriteLine("请输入一个数:");
int x = Convert.ToInt32(Console.ReadLine());
string s = "";
string t = "Δ";
// string p = "→_→";
for (int k = 0; k < x; k++)//左下三角
{
for (int l = 0; l <= k; l++)
{
Console.Write(t);
}
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int m = 0; m < x; m++)//左下三角
{
for (int n = m; n >= 0; n--)
{
Console.Write(t);
}
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int mo = 0; mo < x; mo++)//左上三角
{
for (int no = 0; no < x - mo; no++)
{
Console.Write(t);
}
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int ml = 0; ml < x; ml++)//左上三角
{
for (int io = x - ml; io > 0; io--)
{
Console.Write(t);
}
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int i = 0; i < x; i++)//尖三角形
{
for (int k = 0; k<x-i; k++)
{
Console.Write(" ");
}
s = s + t;
Console.Write(s);
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int i = 0; i < x; i++)//右下三角
{
for (int k = 0; k < x - i; k++)
{
Console.Write(" ");
}
s = s + t;
Console.Write(s);
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int i = 0; i < x; i++)//右上三角
{
for (int k = 0; k <=i; k++)
{
Console.Write(" ");
}
for (int k = 0; k <x- i; k++)
{
Console.Write(t);
}
Console.WriteLine();
}
Console.WriteLine("--------------------");
s = "";
for (int i = 0; i < x-1; i++)//菱形上部
{
for (int k = x; k > i+1; k--)
{
Console.Write(" ");
}
for (int k = 2*x; k >2 * (x - i)-1; k--)
{
Console.Write(t);
}
Console.WriteLine();
}
for (int i = 0; i < x; i++)//菱形下部
{
for (int k = 0; k < i; k++)
{
Console.Write(" ");
}
for (int k = 0; k <2*( x - i)-1; k++)
{
Console.Write(t);
}
Console.WriteLine();
}
Console.ReadKey();