Tuesday, 22 April 2014

HOW TO PRINT DIAMOND SHAPE WITH STARS IN C SHARP

HOW TO PRINT DIAMOND SHAPE WITH STARS IN C SHARP ?

DESCRIPTION: 

IN THIS I AM GOING TO SHOW HOW TO DISPLAY DIAMOND SHAPE IN CONSOLE APPLICATION WITH STARS IN C#

OPEN CONSOLE APPLICATION 
(Program.cs)


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

namespace DIMOND
{
    class Program
    {
        static void Main(string[] args)
        {

            int i, j, n;
            Console.WriteLine("Enter no for printing star in diamond shape");
            n = int.Parse(Console.ReadLine());
            for (i = 1; i <= n; i++)
            {
                for (j = n; j >= i; j--)
                {
                    Console.Write(" ");
                }
                for (j = 1; j <= i; j++)
                {
                    Console.Write("*");
                }
                for (j = 1; j <= i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }


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

OUTPUT:







5 comments:

  1. Hey its very amazing i was trying from last two months i was not getting this thank u for giving this code.
    For similar type of c# interview questions i can prefer you to visit this link also
    c# interview questions

    ReplyDelete
  2. Replies
    1. If you have any doubts in .net you comment here i will clarify that doubts

      Delete
    2. This comment has been removed by the author.

      Delete
  3. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in C SHARP, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on C SHARP. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/




    ReplyDelete

Receive All Free Updates Via Facebook.