【发布时间】:2014-06-04 18:48:44
【问题描述】:
我将如何创建一种机制来传递正整数并显示操作数、操作数的斐波那契数列以及斐波那契数列的所有值的总和,直到并包括指定值?
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="main.css"/>
<title>Fib Activity 3</title>
</head>
<body>
<h1>Pick Category Using GET</h1>
<a href="ISDWK4.php?cat=Films">Films</a>
<a href="ISDWK4.php?cat=Music">Music</a>
<a href="ISDWK4.php?cat=Books">Books</a>
<br />
<h2>Fibonacci</h2>
<form method="get" action="fib3.php">
<fieldset>
<label for="powerof">Fibonacci: </label>
<input type="text" name="powerof" value="<?php echo $_GET['powerof']; ?>"/>
<input type="submit" name='Go' value="Calculate" />
</fieldset>
</form>
<?php
$message = 'The fibonacci sequence is: <br />1<br />2<br />';
$powerof = 0;
$max = 10;
$temp = $max;
if (isset($_GET['powerof'])) {
$powerof = $_GET['powerof'];
}
if ($powerof > 100) {
$powerof = 100;
$message = 'Sorry, your input was too high. I converted it to the maximum value of 100.<br />The fibonacci sequence is: <br />1<br />2<br />';
}
$x = 0;
$y = 1;
$z = 0;
$counter = 0;
while ($counter < $powerof) {
if ($counter <= 1) {
$z = 1;
} else {
$z = $x + $y;
}
echo ($z. "<br />");
$x = $y;
$y = $z;
$counter++;
}
?>
</body>
</html>
感谢所有帮助
【问题讨论】:
-
这是一个不同的阶段,是的,因为我正在从事 5 项活动并慢慢将我的工作提升到下一项
标签: php html numbers sum fibonacci