Page 1 of 1
Pascal triangle
Posted: Tue May 03, 2005 12:08 pm
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
Posted: Tue May 03, 2005 12:54 pm
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...
Posted: Tue May 03, 2005 1:26 pm
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.
Posted: Tue May 03, 2005 8:24 pm
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.
Posted: Wed May 04, 2005 9:42 pm
by asi0917
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
Posted: Wed May 04, 2005 10:05 pm
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
