Advertisement
ivan_yosifov

Pascal_Triangle

Dec 10th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2.  
  3. class PascalTriangle
  4. {    
  5.     static void Main()
  6.     {
  7.         const int Height = 12;
  8.         long[][] triangle = new long[Height + 1][];
  9.  
  10.         for (int row = 0; row < Height; row++)
  11.         {
  12.             triangle[row] = new long[row + 1];
  13.         }
  14.  
  15.         triangle[0][0] = 1;
  16.         for (int row = 0; row < Height - 1; row++)
  17.         {
  18.             for (int col = 0; col <= row; col++)
  19.             {
  20.                 triangle[row + 1][col] += triangle[row][col];
  21.                 triangle[row + 1][col + 1] += triangle[row][col];
  22.             }
  23.         }
  24.  
  25.         for (int row = 0; row < Height; row++)
  26.         {
  27.             Console.Write("".PadLeft((Height - row) * 2));
  28.             for (int col = 0; col <= row; col++)
  29.             {
  30.                 Console.Write("{0,3} ", triangle[row][col]);
  31.             }
  32.             Console.WriteLine();
  33.         }
  34.        
  35.        
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement