Advertisement
SumitParakh

Swaastik

Nov 14th, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. //Make a swaastik
  2.  
  3. using System;  
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace Swaastik
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Console.Write("Enter any number : ");
  15.             int i;
  16.             if(int.TryParse(Console.ReadLine(),out  i))
  17.             {
  18.                 int x = 0, y = 3;
  19.                 bool[] id = new bool[] {false,true};
  20.            
  21.                 for (int j = 0; j < i; j++)
  22.                 {
  23.                     Console.SetCursorPosition(x, y++);
  24.                     Console.Write("*");
  25.                         if (j == i - 1 && id[0]==false )
  26.                         {
  27.                             Console.CursorLeft = 0;
  28.                                 for (j = 0; j < 2 * i - 1; j++)
  29.                                     Console.Write("*");
  30.                             x = Console.CursorLeft - 1;
  31.                             y = Console.CursorTop;
  32.                             j = -1;
  33.                             id[1] = !(id[0]=true);
  34.                         }
  35.                         if (id[0] == true&&id[1]==false )
  36.                         {
  37.                             id[1] = true;
  38.                             continue;
  39.                         }
  40.                 }
  41.                 x = 2 * i - 1;
  42.                 y = 3;            
  43.                 int left;
  44.                 id[1] = !(id[0]=false);
  45.                 for (int j = 0; j < i; j++)
  46.                 {
  47.                     Console.SetCursorPosition(--x, y);
  48.                     Console.Write("*");
  49.                     left=Console.CursorLeft-1;
  50.                         if(j==i-1 && id[0]==false)
  51.                         {
  52.                             Console.CursorLeft--;
  53.                                 for (j = 0; j < 2 * i - 1; j++)
  54.                                 {
  55.                                     Console.SetCursorPosition(left, j + 3);
  56.                                     Console.Write("*");
  57.                                 }
  58.                             j = 0;
  59.                             id[1] = !(id[0]=true);
  60.                         }
  61.                         if (id[0] == true&&id[1]==false )
  62.                         {
  63.                             y = Console.CursorTop;
  64.                             continue;
  65.                         }
  66.                 }
  67.                 Console.CursorTop = 3 + 2 * i - 1;
  68.                 Console.WriteLine();
  69.             }
  70.             else
  71.             {
  72.                 Console.WriteLine("Please enter a valid number...");
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement