Wednesday 30 October 2013

Simple ways to get a Pascal Triangle in C#

using System;

using System.Collections.Generic;

using System.Text;

namespace PascalTriangle

{

   class PascalTriangle

   {

      static void Main(string[] args)

      {

         System.Console.WriteLine("Pascal Triangle Program");

         System.Console.Write("Enter the number of rows: ");

         string input = System.Console.ReadLine();

         int n = Convert.ToInt32(input);

        for(int i=0; i<n; i++)
        {
            int c=1;
            for(int j=0; j<=i; j++)
            {
                System.Console.Write(c);
                c=c*(i-j)/(j+1);
                   System.Console.Write(" ");
            }
           System.Console.Write("\n");
           
        }
            System.Console.WriteLine();

        System.Console.WriteLine();

      }

   }

}

1 comment:

  1. http://www.kidsfront.com/ hurry up visit he site and grab the study material

    ReplyDelete