2011-05-30T07:22:01-04:00
How to I make a program which prints * in diamond in C#?
1
2011-06-10T10:19:47-0400
Using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Diamond { class Program { static void Main(string[] args) { //you can various this 2 parameters of diamond //maximum count = 80 becouse console has 80 columns //minimum height1 = count / 2 becouce arc of diamond is 45degrees const int height1 = 7; const int count = 50; //conumn of diamond /* ****** * ******** * ********** - there height1 is 3. * ******** * ****** * **** * ** and height2 = count / 2 = 10 / 2 =5 */ for (int k = 0; k < height1; k++) { for (int i = 0; i < height1 - k; i++) Console.Write(" "); for (int i = height1 - k; i < count - height1 + k; i++) Console.Write("*"); if (k < height1) Console.WriteLine(); } const int height2 = count / 2; for (int k = height2; k > 0 ; k--) { for (int i = 0; i < height2 - k; i++) Console.Write(" "); for (int i = height2 - k; i < count - height2 + k; i++) Console.Write("*"); Console.WriteLine(); } } } }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C#
Comments