Pascal triangle

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
asi0917
Forum Commoner
Posts: 41
Joined: Thu Nov 25, 2004 10:37 am
Location: Shoreline, Washington
Contact:

Pascal triangle

Post by asi0917 »

for extra credit i have been given the option of creating a php script that will print out a ppascal triangle
ex.
1
11
121
1331
14641

and im wondering if there is a funtion i don't know about that will allow me to create variables within a for loop?

i would include the code i have soo far but thaats on another computer, i may edit this post at lunch
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the first link i found:
http://mathworld.wolfram.com/PascalsTriangle.html

explains all you need to implement it....

a little websearch will probably give you some code too...
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

yes there is code on the web but since this is a project for extra credig I won't give you the url, would kind of defeat the purpose.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

...and im wondering if there is a funtion i don't know about that will allow me to create variables within a for loop?
? You can create variables anywhere:

Code: Select all

$foo = 3;
for ($i=0; $i<4; $i++) {
  $bar = 5;
  if ($bar) {
    $baz = 8;
    echo $bar;
  }
}
I don't believe I understand your question.
User avatar
asi0917
Forum Commoner
Posts: 41
Joined: Thu Nov 25, 2004 10:37 am
Location: Shoreline, Washington
Contact:

Post by asi0917 »

timvw wrote:the first link i found:
http://mathworld.wolfram.com/PascalsTriangle.html

explains all you need to implement it....

a little websearch will probably give you some code too...
your response was the most helpful,
i think theres a way i can plot the numbers of the triangle on a proverbial "grid" using Mersenne numbers and Fibonacci numbers but i don't have to time to spew some code right now

thanks for the help
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

well, i browsed a little more and i found some fine php code quite easily...
but i'm not going to do your homework. good luck :)
Post Reply