You must Sign In to post a response.

Pascal triangle progaam in C# console application

How to code the "Pascal triangle" progaam in C# console application.

Formula:Pij = Pi-1, j-1 + Pi-1, j

output: 1
1 1
1 2 1
1 3 3 1


Comments

Author: Giribabu26 Sep 2008 Member Level: Gold   Points : 5

Generating Pascal Triangle

using System;
class pascalTriangle
{
public static void Main()
{
int binom=1,q=0,r,x;
Console.WriteLine("Enter the number of rows");
string s=Console.ReadLine();
int p =Int32.Parse(s);
Console.WriteLine(p);
Console.WriteLine("The Pascal Triangle");
while(q{
for(r=40-(3*q);r>0;--r)
Console.Write(" ");
for(x=0;x<=q;++x)
{
if((x==0)||(q==0))
binom=1;
else
binom=(binom*(q-x+1))/x;
Console.Write(binom);
}
Console.Write("\n ");
++q;
}
}
}