C# 中的各種星形圖案程式
與其他程式語言(如 C、C++、Java)一樣,我們可以在 C# 中輕鬆顯示星形圖案程式。

我們逐一瞭解它們。
示例
using System.IO;
using System;
class Program {
static void Main() {
for (int i = 1; i <= 6; ++i) {
for (int j = 1; j <= i; ++j) {
Console.Write("*");
}
Console.WriteLine();
}
}
}輸出
* ** *** **** ***** ******
我們來看另一個系列。
示例
using System.IO;
using System;
class Program {
static void Main() {
int i, j, k;
int n = 6,
// loop to print the series
for (i = 1; i <= n; i++) {
for (j = 1; j <= n - i; j++) {
Console.Write(" ");
}
for (k = 1; k <= i; k++) {
Console.Write("*");
}
Console.WriteLine("");
}
Console.ReadLine();
}
}輸出
* ** *** **** ***** ******
我們來看另一個系列。
示例
using System.IO;
using System;
class Program {
static void Main() {
for (int i = 6; i >= 1; --i) {
for (int j = 1; j >= i; ++j) {
Console.Write("*");
}
Console.WriteLine();
}
}
}輸出
****** ***** **** *** ** *
這裡還有另一個系列。
示例
using System.IO;
using System;
class Demo {
static void Main() {
int a = 1, spaces, k = 6, i = 0, j = 0;
spaces = k - 1;
for(i=1; i<k*2; i++) {
for(j=1; j<=spaces; j++) {
Console.Write(" ");
}
for(j=1; j<a*2; j++) {
Console.Write("*");
}
Console.WriteLine("");
if(i < k) {
spaces--;
a++;
} else {
spaces++;
a--;
}
}
}
}輸出
* *** ***** ******* ********* *********** ********* ******* ***** *** *
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP