Friday 21 October 2011

Print triangle without for loop

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

            int i = 1;
        A: if (i < 7)
            {
                pro(i);
                i++;
                goto A;
            }
            int l = 6;
        D: if (l > 0)
            {
                pro1(l);
                l--;
                goto D;

            }

            Console.Read();
        }

        protected static void pro(int j)
        {
            int k = 1;
        B:
            if (k < j)
            {
                Console.Write(k);

                k++;
                goto B;
            }
            Console.WriteLine();

        }

        protected static void pro1(int j)
        {
            int k = 1;
        C:
            if (k < j)
            {
                Console.Write(k);

                k++;
                goto C;
            }
            Console.WriteLine();

        }
    }

out put is
1
12
123
1234
12345
12345
1234
123
12
1

No comments:

Post a Comment