信息采集:
单纯用*号输出上下三角形和菱形,需要用到嵌套循环结构:
代码如下(本人新手,若有错误,请高手指点):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpTest
{
class Program
{
static void Main(string[] args)
{
//左下三角形
for (int i = 0; i <= 9; i++)
{
for (int ii = i; ii <= 9; ii++)
{
Console.Write("*");
}
Console.WriteLine();
}
//右下三角形
for (int i = 0; i <= 9; i++)
{
for (int ii = 0; ii < i; ii++)
{
Console.Write(" ");
}
for (int iii = 0; iii <= (9 - i); iii++)
{
Console.Write("*");
}
Console.WriteLine();
}
//左上三角形
for (int i = 0; i <= 9; i++)
{
for (int ii = 0; ii <= i; ii++)
{
Console.Write("*");
}
Console.WriteLine();
}
//右上三角
for (int i = 0; i <= 9; i++)
{
for (int ii = 0; ii <=(9- i); ii++)
{
Console.Write(" ");
}
for (int iii = 0; iii <= i; iii++)
{
Console.Write("*");
}
Console.WriteLine();
}
//菱形
for (int i = 0; i <= 4; i++)
{
for (int ii = 0; ii <= (4 - i); ii++)
{
Console.Write(" ");
}
for (int ii = 0; ii <= i; ii++)
{
Console.Write("*");
}
for (int ii = 0; ii < i; ii++)
{
Console.Write("*");
}
Console.WriteLine();
}
for (int i = 0; i <= 5; i++)
{
for (int ii = 0; ii < i; ii++)
{
Console.Write(" ");
}
for (int iii = 0; iii <= (5 - i); iii++)
{
Console.Write("*");
}
for (int ii = i; ii <= 4; ii++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.Read();
}
}
}
运行结果: