當前位置:編程學習大全網 - 編程語言 - 用php語言編程:輸出壹個由“*”符號組成的菱形圖形(必須使用for循環語句)

用php語言編程:輸出壹個由“*”符號組成的菱形圖形(必須使用for循環語句)

我的是C#編的,語言不重要,關鍵是掌握方法,我晚自習想了兩節課後自己想到了原創的算法(雖然回家調試沒得到菱形,但很快就修改成功了)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace 字符圖案輸出

{

class Program

{

static void Main(string[] args)

{

bool b = true;

while (b == true)

{

try//判斷數據是否合法↓

{

Console.Write("請輸入壹個奇數: ");

int n = Convert.ToInt32(Console.ReadLine());

if (n % 2 == 0)

{

continue;

}

for (int i = 1; i <= (2 * n) -1; i++)

{

for (int j = 1; j <= Math.Abs(n - i); j++)//絕對值實現對稱, 如:3210123,想想,◆是不是先輸出空格,並逐行減少, 後逐行增多

{

Console.Write(' ');

}

for (int k = 1; k <= Math.Abs(n - Math.Abs(n - i)); k++)//同理,◆第壹行輸出1個*,後逐行增多,然後又逐行減少

{

Console.Write("* ");//如果*後沒有空格,則是半個菱形

}

Console.WriteLine();

}

}

catch

{

b = true;

}

}

}

}

}

  • 上一篇:看似普通實則驚艷的6個網站
  • 下一篇:特斯拉召回870輛ModelX
  • copyright 2024編程學習大全網