write a program to print Pascal Triangle
For example:
Input:
3
Output:
1
1 1
1 2 1
Solution:
using System;
namespace PascalTraingle
{
class Program
{
public static void Main()
{
Console.WriteLine("Enter a number:");
var rows = Convert.ToInt32(Console.ReadLine());
for (var i = 0; i < rows; i++)
{
var val = 1;
for (var j = 0; j <= i; j++)
{
Console.Write(val + " ");
val = val * (i - j) / (j + 1);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}