Every day is wonderful

分享与创新 并大胆的去尝试新鲜事物。。。。

C# 做不同形状的杨辉三角........


这都是Windows控制台下的东西!
第一种是根据网上的方法 自己改的!
其后几种是同学不知道从哪抄的!
弄来 收藏下 算是一种思路吧!

第一种:
namespace mywinfrom_four
{
class Program
{
static void Main(string[] args)
{
int i, x;
for (i = 1; i <= 15; i++)
{
for (x = 1; x <= i; x++)
{
Console.Write(“*”);
}
Console.Write(“\n”);
}

}
}
}

图例一:

第二种:
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i = 1;
for (int row = 1; row <= 10; row++)
{
for (int col = 1; col <= i; col++)
Console.Write(“*”);

Console.WriteLine();

i++;
}
}

}
}

图例二:

第三种:
namespace new_2
{
class Program
{
static void Main(string[] args)
{
int y = 10;
for (int row = 1; row <= 10; row++)
{
for (int col = 1; col <= y; col++)
Console.Write(“*”);

Console.WriteLine();

y–;
}
}
}
}

图例三:

第四种(未完工):
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i = 1;
for (int row = 1; row <= 10; row++)
{
for (int col = 1; col <= i; col++)
Console.Write(“*”);

Console.WriteLine();

i++;
}
int y = 10;
for (int row = 1; row <= 10; row++)
{
for (int col = 1; col <= y; col++)
Console.Write(“*”);

Console.WriteLine();

y–;
}
}

}
}

图例四:

由代码可以看出来! 第一种利用的是排列 和 \n 的换行参数做出来的!
第二种用的row/col的行于列的参数做的!第三种和第二种只是区别于++/–!
第四种也就是第二种与第三种的集合罢了!

点赞

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注