利用for循环的嵌套输出图形--课后作业
for (int i = 1; i <= 8; i++) { int a, b; for (a = 1; a < i; a++) Console.Write(" "); for (b = 8; b >= i; --b) Console.Write("*"); Console.WriteLine(); } Console.ReadLine();
作业一得到的是这个图形
for (int i = 1; i <= 8; i++) { int a, b, c; for (a = 8; a > i; a--) Console.Write(" "); for (b = 1; b <= i; b++) Console.Write("*"); for (c = 1; c < i; c++) Console.Write("*"); Console.WriteLine(); } for (int i = 1; i <= 7; i++) { int a, b, c; for (a = 1; a <= i; a++) Console.Write(" "); for (b = 7; b >= i; b--) Console.Write("*"); for (c = 7; c > i; --c) Console.Write("*"); Console.WriteLine(); } Console.ReadLine();
作业二得到的是这个图形