1.空心菱形
public static void Main(string[] args) { int hangshu = 11; int yiban = hangshu / 2 + 1; //6 int yibanduo = hangshu / 2; //5 for (int i = 1; i < yiban; i++) { int count = 1; for (int j = i; j < yiban; j++) { //Console.Write("&"); Console.Write(" "); } for (int z = 1; z <= 2 * i - 1; z++) { if (count > 1 && count < 2 * i - 1) { //Console.Write("#"); Console.Write(" "); } else { Console.Write("*"); } count++; } Console.WriteLine(); } for (int i = 1; i < yibanduo; i++) { int count = 1; for (int j = 1; j <= i + 1; j++) { //Console.Write("&"); Console.Write(" "); } for (int z = 0; z < 2 * (yibanduo - i) - 1; z++) { if (count > 1 && count < 2 * (yibanduo - i) - 1) { //Console.Write("#"); Console.Write(" "); } else { Console.Write("*"); } count++; } Console.WriteLine(); } Console.ReadKey(); }
2.输出菱形
public static void Main(string[] args) { Console.Write("请输入多少行?"); int a = int.Parse(Console.ReadLine()); for (int i = 1; i <= a; i++) { for (int j = 1; j <= a - i; j++) { Console.Write(" "); } for (int z = 1; z <= 2 * i - 1; z++) { Console.Write("*"); } Console.WriteLine(); } for (int i = 0; i < a - 1; i++) { for (int j = 0; j <= i; j++) { Console.Write(" "); } for (int z = 0; z < 2 * (a - i - 1) - 1; z++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadKey(); }