Answer to Question #17278 in C# for sandhya sharma
2012-10-25T09:06:02-04:00
Write a program that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character.
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
1
2012-10-26T10:06:04-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { for (int i = 4; i >= -4; i--) { int absVal = Math.Abs(i); PrintSpace(1); PrintSpace(absVal); PrintStar(1 + (4 - absVal) * 2); Console.WriteLine(); } Console.ReadKey(); } static void PrintStar(int count) { for (int i = 0; i < count; i++) { Console.Write("*"); } } static void PrintSpace(int count) { for (int i = 0; i < count; i++) { Console.Write(" "); } } } }
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
Leave a comment