How to Print Pascal triangle in c#

Shubham
Posted by Shubham under C# category on | Points: 40 | Views : 19811
This program will help beginners to write their lab assignment and print the Pascal triangle on consol. you can specify limit of Pascal triangle and the program will calculate the Pascal triangle..

using System;

namespace MyApp
{
class Pascal_class
{
static void Main()
{
int nLimit;
Console.Write("Enter the limit for Pascal Triangle: ");

nLimit = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i < nLimit; i++)
{
int c = 1;
Console.WriteLine(" ");

for (int j = 0; j <= i; j++)
{
Console.Write(c);
Console.Write("");

c = c * (i - j) / (j + 1);
}
Console.Write(" ");
}
Console.Write(" ");
Console.Read();
}
}

}

Comments or Responses

Login to post response