Author Topic: C# Diamond Star Pattern using simple for loops  (Read 5101 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
C# Diamond Star Pattern using simple for loops
« on: June 29, 2011, 03:25:15 pm »
Here is the C# program for Diamond Star Pattern using simple for loops

using System;
using System.Collections.Generic;
using System.Text;

namespace DiamondPattern
{
    class DiamondPattern
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Program for displaying pattern of *.");
            Console.Write("Enter the maximum number of *: ");
            int n = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("\nHere is the Diamond of Stars\n");

          for (int i = 1; i <= n; i++)
          {
             for (int j = 0; j < (n - i); j++)
                Console.Write(" ");
             for (int j = 1; j <= i; j++)
                Console.Write("*");
             for (int k = 1; k < i; k++)
                Console.Write("*");
             Console.WriteLine();
          }

          for (int i = n - 1; i >= 1; i--)
          {
             for (int j = 0; j < (n - i); j++)
                Console.Write(" ");
             for (int j = 1; j <= i; j++)
                Console.Write("*");
             for (int k = 1; k < i; k++)
                Console.Write("*");
             Console.WriteLine();
          }
         
          Console.WriteLine();
        }
    }
}



 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1