2011-06-24 20 views
0

私はCISカレッジクラスの問題に取り組んでいます。 forループとConsole.Write( "")のみを使用して、4つの三角形のアスタリスクを描画します。およびConsole.WriteLine();ここでC#Triangle Program質問

は、画像へのリンク

Triangles

私が必要とするよりも、1つの余分のスペースがあります。

class Diamond 
    { 
     static void Main(string[] args) 
     { 
      int row; // the current row 
      int stars; // the number of stars 
      int spaces; // the number of spaces 

      // top half (1st five lines) 
      for (row = 1; row <= 11; row++) 
      { 
      for (spaces = 1; spaces > row; spaces--) 
      Console.Write(" "); 

       for (stars = 1; stars <= row - 1; stars++) 
        Console.Write("*"); 

        Console.WriteLine(); 
        } // end outer for 


      //Triangle B 

      for (row = 0; row <= 11; row++) 
      { 
       Console.WriteLine(); 
       for (spaces = 10; spaces > row; spaces--) 
        Console.Write("*"); 

       for (stars = 1; stars <= row - 1; stars++) 
        Console.Write(""); 
      } // end outer for 

      //Triangle C 

      for (row = 0; row <= 11; row++) 
      { 
       for (stars = 0; stars <= row - 1; stars++) 
        Console.Write(" "); 

       for (spaces = 10; spaces > row; spaces--) 
        Console.Write("*"); 

       Console.WriteLine(); 
      } // end outer for 


      //Triangle D 

      for (row = 1; row <= 10; row++) 
      { 
       for (spaces = 10; spaces > row; spaces--) 
        Console.Write(" "); 

       for (stars = 0; stars <= row - 1; stars++) 
        Console.Write("*"); 

       Console.WriteLine(); 
      } // end outer for 


      Console.ReadLine(); 
     } // end Main 
    } // end class Diamond 

私の問題のヒントや解決策はありますか?

+0

インデックスで遊んでみましたか? –

答えて

0

私はそれが何か簡単だと分かっていました!

三角形cのスペース= 10を11に変更し、残りのすべてと同様に行= 1にしました。

あなたの有益なヒントをありがとう=)