-
-
Save SonnyRR/e4531e1e3079904dec9beb359f930028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace SandBox | |
{ | |
using System; | |
public class EntryPoint | |
{ | |
public static void Main() | |
{ | |
long triangleRows = long.Parse(Console.ReadLine()); | |
long[][] jaggedArray = new long[triangleRows][]; | |
jaggedArray[0] = new long[1]; | |
jaggedArray[0][0] = 1; | |
for (long row = 1; row < jaggedArray.Length; row++) | |
{ | |
jaggedArray[row] = new long[row + 1]; | |
jaggedArray[row][0] = 1; | |
jaggedArray[row][jaggedArray[row].Length - 1] = 1; | |
for (long col = 1; col < jaggedArray[row].Length - 1; col++) | |
{ | |
long leftDiagonal = jaggedArray[row - 1][col - 1]; | |
long rightDiagonal = jaggedArray[row - 1][col]; | |
jaggedArray[row][col] = leftDiagonal + rightDiagonal; | |
} | |
} | |
for (long row = 0; row < triangleRows; row++) | |
{ | |
Console.WriteLine(string.Join(" ", jaggedArray[row])); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment