Monday 10 December 2012

Code for All types of Patterns

           WAP to draw a following pattern : 
            ////////////////////////////               *
            ////////////////////////////              **
            ////////////////////////////             ***
            ////////////////////////////            ****
            ////////////////////////////           *****
            //for (int i = 1; i <= 5; i++)
            //{

            //    for (int j = i; j < 5; j++)
            //    {
            //        Console.Write(" ");
            //    }

            //    for (int k = 1; k <= i; k++)
            //    {
            //        Console.Write("*");

            //    }
            //    Console.WriteLine("\n");
            //}


            WAP to draw a following pattern : 
            ////////////////////////////      *****
            ////////////////////////////      ****
            ////////////////////////////      ***
            ////////////////////////////      **
            ////////////////////////////      *
            ////////////////////////////      *****
            ////////////////////////////       ****  
            ////////////////////////////        ***
            ////////////////////////////         **
            ////////////////////////////          *

            //for (int row = 5; row >= 1; --row)
            //{
            //    for (int col = 1; col <= row; ++col)
            //    {
            //        Console.Write("*");
            //    }

            //    Console.WriteLine();
            //}

            //Console.WriteLine();

            //for (int row = 5; row >= 1; --row)
            //{
            //    for (int spaces = 0; spaces < 5 - row; ++spaces)
            //    {
            //        Console.Write(" ");
            //    }

            //    for (int col = 1; col <= row; ++col)
            //    {
            //        Console.Write("*");
            //    }

            //    Console.WriteLine();
            //}

           WAP to draw a following pattern : 
            /////////////////////////////////. *
            //////////////////////////////   ***
            /////////////////////////////  *****
            ///////////////////////////// *******
            ////////////////////////////*********

            //int row, c, n, temp;
            //Console.WriteLine("Enter the number of rows in pyramid of stars you wish to see ");
            //n = int.Parse(Console.ReadLine());
            //temp = n;
            //for (row = 1; row <= n; row++)
            //{
            //    for (c = 1; c < temp; c++)
            //        Console.Write(" ");

            //    temp--;

            //    for (c = 1; c <= 2 * row - 1; c++)
            //        Console.Write("*");

            //    Console.WriteLine("\n");
            //}


            WAP to draw a following pattern : 
            ////////////////////////////    1
            ////////////////////////////    0 1
            ////////////////////////////    1 0 1
            ////////////////////////////    0 1 0 1
            ////////////////////////////    1 0 1 0 1

            //int i, j,k;
            //Console.WriteLine("Enter the number of rows u wish to see :");
            //int n = int.Parse(Console.ReadLine());
            //for (i = 1; i <= n; i++)
            //{
            //    for (j = 1; j <= i; j++)
            //    {
            //        if (i % 2 == 0)
            //        {
            //            if (j % 2 == 0)
            //            {
            //                k = 1;
            //                Console.Write(k);
            //            }
            //            else
            //            {
            //                k = 0;
            //                Console.Write(k);
            //            }
            //        }
            //        else
            //        {
            //            if (j % 2 == 0)
            //            {
            //                k = 0;
            //                Console.Write(k);
            //            }
            //            else
            //            {
            //                k = 1;
            //                Console.Write(k);
            //            }
            //        }
            //    }
            //    Console.WriteLine();
            //}

           WAP to draw a following pattern : 
            ////////////////////////////////    *
            ///////////////////////////////   *A*
            //////////////////////////////  *A*A*
            //////////////////////////// *A*A*A*

            //int i, j, temp, count = 1;
            //Console.WriteLine("Enter number of rows \n");
            //int n = int.Parse(Console.ReadLine());
            //temp = n;
            //for (i = 1; i <= n; i++)
            //{
            //    for (j = 1; j < temp; j++)
            //        Console.Write(" ");
            //    temp--;
            //    for (j = 1; j <= i; j++)
            //    {
            //        Console.Write("*");

            //        if (i > 1 && count < i)
            //        {
            //            Console.Write("A");
            //            count++;
            //        }
            //    }
            //    Console.WriteLine("\n");
            //    //temp--;
            //    count = 1;
            //}


            WAP to draw a following pattern : 
            //////////////////////////////  1
            //////////////////////////////  22
            //////////////////////////////  333
            //////////////////////////////  4444
            //////////////////////////////  55555

            //int i, j;
            //Console.Write("Enter number of rows : ");
            //int n = int.Parse(Console.ReadLine());
            //for (i = 1; i <= n; i++)
            //{
            //    for (j = 1; j <= i; j++)
            //        Console.Write(i);

            //    Console.WriteLine("\n");
            //}


            WAP to draw a following pattern : 
            ////////////////////////////        *******
            ////////////////////////////        ***S***
            ////////////////////////////        **SSS**
            ////////////////////////////        *SSSSS*

            //int  i, j, space, temp;
            //Console.Write("Enter number of rows :");
            //int n = int.Parse(Console.ReadLine());
            //space = 1;
            //temp = n - 1;
            //for (i = 1; i <= 2 * n - 1; i++)
            //    Console.Write("*");
            //Console.WriteLine("\n");
            //for (j = 2; j <= n; j++)
            //{
            //    for (i = 1; i <= temp; i++)
            //        Console.Write("*");
            //    for (i = 1; i <= space; i++)
            //        Console.Write("S");
            //    space = 2 * j - 1;

            //    for (i = 1; i <= temp; i++)
            //        Console.Write("*");
            //    temp--;
            //    Console.WriteLine("\n");
            //}

           WAP to draw a following pattern : 
            ////////////////////////////////////      1
            ////////////////////////////////////      232
            ////////////////////////////////////      34543
            ////////////////////////////////////      4567654
            ////////////////////////////////////      567898765

            //int n, c, d, num = 1, space;

            //n = int.Parse(Console.ReadLine());

            //space = n - 1;

            //for (d = 1; d <= n; d++)
            //{
            //    num = d;

            //    for (c = 1; c <= space; c++)
            //        Console.Write(" ");

            //    space--;

            //    for (c = 1; c <= d; c++)
            //    {
            //        Console.Write(num);
            //        num++;
            //    }
            //    num--;
            //    num--;
            //    for (c = 1; c < d; c++)
            //    {
            //        Console.Write(num);
            //        num--;
            //    }
            //    Console.WriteLine("\n");

            //}

No comments:

Post a Comment