Example:
Doing Factorial in HTML and PHP
<!DOCTYPE html
PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Factorial with Using PHP</title>
</head>
<body>
<form id="form1" name="factForm" method="post" action="factorial.php">
<p>Factorial
with php</p>
<label id="lbl01">Enter
integer</label>
<input type="text" name="number" />
<input type="submit" name="button" />
</form>
</body>
</html>
|
<!DOCTYPE html
PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Factorial in PHP</title>
</head>
<body>
<?php
function fact($i){
if ($i == 0){
return 1;
}
else {
return $i * fact($i - 1);
}
}
$num = $_POST['number'];
echo "The number entered is
".$num."</br>";
echo
"The answer is ".fact($num).".";
?>
</body>
</html>
|
No comments:
Post a Comment