菱形を出力
問題
例にある菱形を出力しましょう。
……ちゃんとfor文とか使いましょうね。
コピーして全部にprintfとか付けちゃだめですよ。
例
* * *** *** ***** ***** ******* ******* ********* ********* *********** ********* ********* ******* ******* ***** ***** *** *** * *
解答例
using System; namespace Rhombus { class Program { static void Main(string[] args) { const int height = 5; const int step = 2; for (int h = -height; h <= height; h++) { int absh = Math.Abs(h); int spaceNum = absh; int starNum = 2 * (height - absh) + 1; int stepNum = (h == 0 ? 1 : step); for (int s = 0; s < stepNum; s++) { for (int space = 1; space <= spaceNum; space++) { Console.Write(" "); } for (int star = 1; star <= starNum; star++) { Console.Write("*"); } Console.WriteLine(); } } } } }