We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, June 17, 2015

MASTER PASCAL TRIANGLE




class Pattern
    {
        static void Main()
        {
            int row, space, n, coll;
            Console.WriteLine("Enter the number of rows : ");
            n = int.Parse(Console.ReadLine());
            for (row = 0; row <= n; row++)
            {
                Console.Write("  ");
                for (space = 1; space <= (n - row); space++)
                    Console.Write("  ");

                for (coll = 0; coll <= row; coll++)
                    Console.Write(factorial(row) / (factorial(coll) * factorial(row - coll)) + "   ");
                Console.WriteLine();

            }
           
            Console.ReadLine();
        }

        static int factorial(int n)
        {
            int c;
            int result = 1;

            for (c = 1; c <= n; c++)
                result = result * c;
            return (result);

        }

    }


No comments: