My first PHP routine - almost works but not quite !!!
Posted: Thu Nov 12, 2009 12:17 pm
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Dear All,
I have been teaching myself PHP - with some success. However, the following piece of code does not do what I thought it would. I wanted it to return the factorial values of the integers up to 10. Instead it just returns 0. Can anybody tell me why ? thanks
Kaps
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Dear All,
I have been teaching myself PHP - with some success. However, the following piece of code does not do what I thought it would. I wanted it to return the factorial values of the integers up to 10. Instead it just returns 0. Can anybody tell me why ? thanks
Kaps
Code: Select all
<?php
// Title : My first PHP script
// Author : Kaps
function factorial($num){
STATIC $factorial_Value;
$factorial_value = $factorial_value * $num;
printf(" factorial %d has the value %d </br>",$num,$factorial_value);
}
$upper=10;
for($i=1;$i<=$upper;$i++)
{
printf(" value of i %d </br> ",$i);
factorial($i);
}
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: