programming-examples/c-sharp/Mathematics/C# Program to Illustrate Pascal Triangle.cs

39 lines
995 B
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C# Program to Illustrate Pascal Triangle
*/
using System;
class Pascal
{
public static void Main()
{
int[,] arr = new int[8, 8];
Console.WriteLine("Pascal Triangle : ");
for (int i = 0; i < 5; i++)
{
for (int k = 5; k > i; k--)
{
Console.Write(" ");
}
for (int j = 0; j < i; j++)
{
if (j == 0 || i == j)
{
arr[i, j] = 1;
}
else
{
arr[i, j] = arr[i - 1, j] + arr[i - 1, j - 1];
}
Console.Write(arr[i, j] + " ");
}
Console.ReadLine();
}
}
}
/*
Pascal Triangle :
1
1 1
1 2 1
1 3 3 1