Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Pritom Nandy
More...

Forums » .NET » .NET »

Pascal triangle progaam in C# console application


Posted Date: 25 Sep 2008      Posted By:: Kumaresh     Member Level: Gold    Member Rank: 598     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: 348     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.



Next : Negative fibonacci series and fibonacci series in C#.net
Previous : Add integer values to an array + console application using c#
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.