Click here to Skip to main content
15,883,922 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a program to display diamond pattern. Number of rows of diamond would be equal to the input value entered by user. That is what i have done. But lower part of diamond is not printing mirror image of upper part?
Here is my program:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace diamonddemo
{
    class Program
    {
        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 = 0; i < n; i= i+2) {
                for (int j = 0; j<=i; j++)
                Console.Write("*");         
                Console.WriteLine();
               }
               for (int i = n-1; i>=1; i=i-2)
               {
                   for (int j = 0; j<(n-i); j++)
                       Console.Write("*");
                   Console.WriteLine();
               }
          Console.ReadLine();
      }
    }
}
Posted
Updated 3-Aug-15 22:53pm
v2
Comments
Member 11808002 4-Aug-15 4:18am    
Well mirror image is achieved. chanhge this code for (int i = n-1; i>=1; i=i-2)
{ for (int j = 0; j<(n-i); j++)

with this
for (int i = n-1; i>=1; i=i-2)
{ for (int j = 0; j<(i-1); j++)
DamithSL 4-Aug-15 4:21am    
if you find answer yourself, you can post it as answer to your own question and mark it as answer.

1 solution

Answered only to remove from unanswered list: solved by OP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900