Here is my code to draw a star..But i have a problem..its printing only half star.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace triangle
{
class Program
{
int k = int.Parse(Console.ReadLine());
static void Main(string[] args)
{
Console.WriteLine("Enter The Value:");
int k = int.Parse(Console.ReadLine());
int m = k;
int n = k - 1;
int y = n;
int x = 2 * (k - 1) + 1;
int q = x;
// code for writing triangle
for (int p = 0; p <= n; p++)
{
for (int j = k - 1; j >= 0; j--)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" ");
}
for (int i = 0; i <= (x - 2 * (k - 1)); i++)
{
if ((i % 2 == 1 && i == 1) || (i % 2 == 1 && i == (x - 2 * (k - 1))) || (i % 2 == 1 && p == n))
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
k--;
}
// the parameter values will be changed hence initializing again
k = m;
x = q;
n = y;
Console.SetCursorPosition(0,((k/2)));
// code for writing reverse triangle
for (int p = n; p >= 0; p--)
{
for (int j = k-1; j <= n+1; j++)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(" ");
}
for (int i = x; i >= (x - 2 * (k - 1)); i--)
{
if ((i % 2 == 1 && i == x) || (i % 2 == 1 && i == (x - 2 * (k - 1))) || (i % 2 == 1 && p == n))
{
Console.Write("*");
}
else
{
if (Console.CursorVisible == true)
{
Console.Write(" ");
}
else
{
Console.Write("*");
}
}
}
Console.WriteLine();
k--;
}
Console.ReadLine();
}
}
}