Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Pascal's Triangle and TriangularArray
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Carey




PostPosted: Mon Apr 07, 2008 7:41 am   Post subject: Pascal's Triangle and TriangularArray

This is a program to generate any term in Pascal's triangle. It also serves as a demonstration of the difference between recursion and memory recursion. (memory keeps track of the values it has generated). I have also included a class called TriangleArray. This is a class specifically designed to handle pyramid-shaped arrays like the numbers in Pascal's triangle and is generic enough to be used in any program that needs it.
To generate a value in Pascal's triangle simply call
Turing:

%show the value of row 10, col 5 of Pascal's triangle
put pascal (10, 5)


To show Pascal's triangle call

Turing:

%show Pascal's triangle
putTriangle


The method putTriangle is there to show Pascal's triangle up to whatever the constant ROWS is. Be carefull to not make rows too big (>33) of you will get an integer overflow error. (you can correct this by changing the 'Data' type at the top of the program to real instead of int). The constant MEMORY dictate wether you want to use memory recursion or not. Try it both ways and notice the speed delay. The constant MID is the middle text col of the screen (don't change). The constant SPACING is the number of text cols each number occupies. Make it an even number for a better looking triangle. The constant ROWS is how may rows of Pascal's triangle you want to generate with putTriangle. The constants MID, SPACING and ROWS are not needed if you are not using the putTriangle method.

Just post if have suggestions or comments of either the TriangleArray class, Pascal stuff, or memory recursion.



Pascal's Triangle - Triangle Array.t
 Description:

Download
 Filename:  Pascal's Triangle - Triangle Array.t
 Filesize:  3.39 KB
 Downloaded:  851 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
petree08




PostPosted: Mon Apr 07, 2008 9:57 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

Pretty cool, my compsci class is starting recursion pretty soon, good to see an example like this
Tallguy




PostPosted: Mon Apr 14, 2008 8:33 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

yoo, very well done, the larger numbers are a bit hard to see though, their too close together
repsoccer16




PostPosted: Tue Apr 15, 2008 7:53 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

ya try to spread the numbers out more for the larger ones.
Carey




PostPosted: Wed Apr 16, 2008 10:14 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

Read the instructions. the spacing controls how far apart each number is. up the spacing to spread out the numbers more
repsoccer16




PostPosted: Thu Apr 17, 2008 7:36 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

sorry bud...could have just said it nicely instead of being rude about it.
Carey




PostPosted: Thu Apr 17, 2008 9:56 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

I wasn't trying to be rude. typing doesn't carry emotion very well. Sorry.
repsoccer16




PostPosted: Mon Apr 21, 2008 7:28 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

that's okay Smile
Sponsor
Sponsor
Sponsor
sponsor
nastynika




PostPosted: Mon May 12, 2008 8:29 am   Post subject: Re: Pascal's Triangle and TriangularArray

how would u amke it so the user can input a colum and row and it would show it?
Carey




PostPosted: Mon May 12, 2008 9:52 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

See the first post

Turing:

%show the value of row 10, col 5 of Pascal's triangle
put pascal (10, 5)
nastynika




PostPosted: Tue May 13, 2008 8:05 am   Post subject: Re: Pascal's Triangle and TriangularArray

no i mean like a get statement or something where u input a ropw and colum while the program is running
Carey




PostPosted: Wed May 14, 2008 10:36 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

just use variables top store the rows and cols that you want to output then use them to call the pascal method

Turing:

var row. col :int
get row
get col
put pascal (row, col)
BrookeTookie




PostPosted: Wed Apr 30, 2014 9:38 am   Post subject: Re: Pascal's Triangle and TriangularArray

Is this program Recursive or non recursive?
Insectoid




PostPosted: Wed Apr 30, 2014 10:14 am   Post subject: RE:Pascal\'s Triangle and TriangularArray

Quote:
It also serves as a demonstration of the difference between recursion and memory recursion.
BrookeTookie




PostPosted: Thu May 01, 2014 10:09 am   Post subject: Re: Pascal's Triangle and TriangularArray

Lol okay, i made a mistake. I was trying to offend anyone or upset anyone by that. I just misread that.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: