fork download
  1. using System;
  2.  
  3. class ShapePrinter
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine("✨ 2025年形状测试程序 ✨\n");
  8.  
  9. // 打印金字塔
  10. int layers = 5;
  11. Console.WriteLine($"正在生成 {layers} 层金字塔:");
  12. PrintPyramid(layers);
  13.  
  14. // 打印对称菱形
  15. Console.WriteLine("\n正在生成对称菱形:");
  16. PrintDiamond(5);
  17.  
  18. Console.WriteLine("\n✅ 测试完成!");
  19. }
  20.  
  21. static void PrintPyramid(int n)
  22. {
  23. for (int i = 0; i < n; i++)
  24. {
  25. Console.Write(new string(' ', n - i - 1));
  26. Console.WriteLine(new string('*', 2 * i + 1));
  27. }
  28. }
  29.  
  30. static void PrintDiamond(int n)
  31. {
  32. // 上半部分
  33. for (int i = 0; i < n; i++)
  34. {
  35. Console.Write(new string(' ', n - i - 1));
  36. Console.WriteLine(new string('*', 2 * i + 1));
  37. }
  38. // 下半部分
  39. for (int i = n - 2; i >= 0; i--)
  40. {
  41. Console.Write(new string(' ', n - i - 1));
  42. Console.WriteLine(new string('*', 2 * i + 1));
  43. }
  44. }
  45. }
  46.  
Success #stdin #stdout 0.06s 29056KB
stdin
Standard input is empty
stdout
✨ 2025年形状测试程序 ✨

正在生成 5 层金字塔:
    *
   ***
  *****
 *******
*********

正在生成对称菱形:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

✅ 测试完成!