Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _2.PascalTriangle
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- int[][] triangleArray = new int[rows][];
- for (int i = 0; i < rows; i++)
- {
- triangleArray[i] = new int[i + 1];
- }
- triangleArray[0][0] = 1;
- Console.WriteLine(triangleArray[0][0]);
- for (int i = 1; i < triangleArray.GetLength(0); i++)
- {
- for (int j = 0; j < triangleArray[i].Length; j++)
- {
- if(j == 0 || j == triangleArray[i].Length - 1)
- {
- triangleArray[i][j] = 1;
- Console.Write(triangleArray[i][j] + " ");
- }
- else
- {
- triangleArray[i][j] = triangleArray[i - 1][j - 1] + triangleArray[i-1][j];
- Console.Write(triangleArray[i][j] + " ");
- }
- }
- Console.WriteLine();
- }
- //foreach(int[] array in triangleArray)
- //{
- // foreach (int position in array)
- // {
- // Console.Write(position + " ");
- // }
- // Console.WriteLine();
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment