第五種 Pattern5
輸出結果如下圖:

整理概念如下:
1.第一個字元為1,依序每增加一列在列首增加1字元、單數列增加1、雙數列增加0。
2.每一列的時候實行檢查( i%2 ),判斷現在在單數列或偶數列。
3.每一行的時候實行檢查( j%2 ),判斷現在在單數行或偶數行。
4.依單數、偶數行列處理顯示字元、確保最後一位元為1。
using System;
namespace Pattern5
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Write("請輸入行數 : ");
int rows = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
if (i % 2 == 0)
{
if (j % 2 == 0)
{
Console.Write(1);
}
else
{
Console.Write(0);
}
}
else
{
if (j % 2 != 0)
{
Console.Write(1);
}
else
{
Console.Write(0);
}
}
}
Console.Write("\n");
}
}
}
}
}
本頁面為一點點累積學習寫程式之路。
許多資訊不是正確、或只是自己看的懂得。
如果不小心點進來誤導了您,還真的不好意思。
