Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Triangle of Pascal

Reply
Thread Tools

Triangle of Pascal

 
 
J Ivan P Silvestre
Guest
Posts: n/a
 
      09-08-2008
c #: Implementing the method Int [,] TrianglePascal (int n) which
returns the triangle to

the level of Pascal N.


public static int[,] TrianglePascal(int n)
{
int[,] arr = new int[n+1,n+1];
for(int i=0;i<n+1;i++)
{
for(int k=0;k<n+1;k++)
{
if(k==0)
arr[i,k]=1;
else if(i==k)arr[i,k]=1;
}
}
for(int i=0;i<n+1;i++)
{
for(int k=0;k<n+1+1;k++){
if(i>=1&&i+1<n+1&&k+1<n+1)
{
if(arr[i,k]!=0&&arr[i,k+1]!=0)
arr[i+1,k+1]=arr[i,k]+arr[i,k+1];
}
}
}
return arr;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pascal's triangle code - Please help! LL C Programming 9 03-30-2009 12:03 PM
Pascal Triangle doubt - Help! pradeep C Programming 30 03-16-2009 09:27 PM
Algorithm for Pascal Triangle dmp C Programming 2 12-10-2008 08:08 AM
Pascal's Triangle Aaron C Programming 4 12-15-2006 11:02 AM
PASCAL'S TRIANGLE GUPTAJI C Programming 25 10-06-2006 05:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57