Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System.Linq;
  2. using System.Text;
  3. using System.Threading.Tasks;
  4.  
  5. namespace PascalTriangle
  6. {
  7.     class Program
  8.     {
  9.         static List<long> pascalList = new List<long> { 0, 1, 0 };
  10.         static List<long> tempList = new List<long>();
  11.         static List<List<long>> pascalTriangle = new List<List<long>>();
  12.         static int LastRowCount=0;
  13.         static int rowsRequired=0;
  14.  
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             Console.WriteLine("Please enter the rows");
  19.             rowsRequired = Convert.ToInt32(Console.ReadLine());
  20.  
  21.             for (int iteration = 0; iteration < rowsRequired; iteration++)
  22.             {
  23.                 IEnumerator<long> enumeratorTwo = pascalList.GetEnumerator();
  24.                 enumeratorTwo.MoveNext();
  25.  
  26.                 tempList.Add(0);
  27.                 foreach (long ele in pascalList)
  28.                 {
  29.                     if (enumeratorTwo.MoveNext())
  30.                         tempList.Add(ele + enumeratorTwo.Current);
  31.                 }
  32.                 tempList.Add(0);
  33.                 pascalList = tempList.ToList<long>();
  34.                 pascalTriangle.Add(pascalList.Where(ele => ele != 0).ToList<long>());
  35.                 tempList.Clear();
  36.             }
  37.  
  38.             LastRowCount = pascalTriangle[pascalTriangle.Count - 1].Count();
  39.  
  40.             foreach (List<long> psclRow in pascalTriangle)
  41.             {
  42.                 for (long i = 0; i < LastRowCount; i++)
  43.                     Console.Write(" ");
  44.                 foreach (long psclRowEle in psclRow)
  45.                     Console.Write(psclRowEle +" ");
  46.  
  47.                 Console.WriteLine();
  48.                 LastRowCount--;
  49.             }
  50.  
  51.             Console.ReadLine();
  52.         }
  53.     }
  54. }