2013-07-12
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, k;
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= 3-i; j++)
{
Console.Write(" ");
}
for (k = 1; k <= 2*i-1; k++)
{
Console.Write("*");
}
Console.WriteLine("");
}
}
}
}
2013-07-12
using System.Collections.Generic;
using System.Text;
namespace demo
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i < 4; i++)
{
for (j = 1; j < i*2-1; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace T
{
class Program
{
static void Main(string[] args)
{
//居中的正等边三角形
Console.WriteLine("行数");
int n = Convert.ToInt32(Console.ReadLine());
//Console.Clear();
string row = "";
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= 2 * i - 1; j++)
{
row += "*";
}
Console.SetCursorPosition((Console.WindowWidth - row.Length) / 2, i);
Console.WriteLine(row);
row = "";
}
//倒三角形
Console.WriteLine("输入行数:");
int rows = Convert.ToInt32(Console.ReadLine());
//先执行while条件语句,在执行单码块内容;
for (int i = rows; i > 0; i--)
{
//循环空格
for (int j = 0; j < rows - i; j++)
{
Console.Write(" ");
}
//循环图形
for (int a = 0; a < 2 * i - 1; a++)
{
Console.Write("*");
}
Console.Write("\n");
}
//正三角形
Console.WriteLine("输入行数:");
rows = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i <= rows; i++)
{
//循环空格
for (int j = 0; j < rows - i; j++)
{
Console.Write(" ");
}
//循环图形
for (int a = 0; a < 2 * i - 1; a++)
{
Console.Write("*");
}
Console.Write("\n");
}
Console.ReadKey();
}
}
}