Forums » .NET » .NET »

Pascal triangle progaam in C# console application


Posted Date: 25 Sep 2008      Posted By:: Kumaresh     Member Level: Gold    Member Rank: 849     Points: 1   Responses: 1



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




Responses

#300595    Author: Giribabu      Member Level: Gold      Member Rank: 341     Date: 26/Sep/2008   Rating: 2 out of 52 out of 5     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<p)
{
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;
}
}
}

--Giri
http://giribabu.wordpress.com


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John

Online Members

Ram Prasad
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India