[c#]代码库
using System;
namespace 右回转三角形
{
class Program
{
static void Main(string[] args)
{
Console.Write("输入三角形边长(字符数):");
int n = int.Parse(Console.ReadLine());
Console.WriteLine();
RotaTrie(n);
Console.ReadLine();
}
/// <summary>
/// 右回转三角形
/// </summary>
/// <param name="n">三角形边长</param>
public static void RotaTrie(int n)
{
int a = 1, k = 13;
for (int i = 0; i <= n; i++)
{
for (int j = 1; j <= k; j++)
Console.Write(" ");
if (i % 2 == 1)
{
a = (i + 1) * (i + 2) / 2;
for (int j = 0; j < i + 1; j++)
Console.Write("{0,3}{1}", a--, " ");
}
else
{
a = i * (i + 1) / 2 + 1;
for (int j = 0; j < i + 1; j++)
Console.Write("{0,3}{1}", a++, " ");
}
Console.WriteLine();
k--;
}
}
}
}