Good I am doing a program that gives you the factorial of a number, I have it resolved in a for
and while
but when wanting to pass it to do while
it does not throw me anything, I do not know why it is unknown a lot about do while
.
This is with for
:
<link rel="stylesheet" href="tablass.css">
<div class="container">
<h2>EJERCICIO DEL FACTORIAL</h2>
<p>Factoriales de numeros</p>
<table class="table">
<thead>
<th></th>
<th></th>
<th> </th>
<th> </th>
<th> </th>
</thead>
<tbody>
<?php
echo"<table border=1 cellspacing=0 width=200";
echo "<tr><th colspan=5> Factorial </th></tr>";
$factorial=1;
$i;
$numero=$_REQUEST['valor1'];
for($i=1;$i<=$numero;$i++){
echo "<tr>";
$factorial=$factorial*$i;
echo "<td>".$factorial. "</td>";
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<html lang="es">
<link rel="stylesheet" href="tablass.css">
<head>
<title> </title>
</head>
<body>
<h1>Factorial del 5 </h1>
<form action="factorial.php" method="post">
<h1>Ingresa un numero</h1>:
<input type="text" name="valor1"><br>
<input type="submit" value="Aceptar">
</form>
</body>
echo"<table BORDER='1'>";
echo"
<tr>
<td colspan=7 align=center>Factorial
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
This is with while
:
<link rel="stylesheet" href="tablass.css">
<div class="container">
<h2>EJERCICIO DEL FACTORIAL</h2>
<p>Factoriales de numeros</p>
<table class="table">
<thead>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</thead>
<tbody>
<?php
echo"<table border=1 cellspacing=0 width=200";
echo "<tr><th colspan=5> Factorial </th></tr>";
$factorial=1;
$i;
$numero=$_REQUEST['valor1'];
while($i<=$numero){
echo "<tr>";
$factorial=$factorial* $i;
echo "<td>" .$factorial. "</td>";
$i++;
}
?>
Here I have the problem with do while
:
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<html lang="es">
<link rel="stylesheet" href="tablass.css">
<div class="container">
<h2>EJERCICIO DEL FACTORIAL</h2>
<p>Factoriales de numeros</p>
<table class="table">
<thead>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</thead>
<tbody>
<?php
echo"<table border=1 cellspacing=0 width=200";
echo "<tr><th colspan=5> Factorial </th></tr>";
$factorial=1;
$numero=$_REQUEST['valor1'];
$i;
do{
echo "<tr> <td align=center>$factorial</td>
<td align=center>x</td>
<td align=center>$i</td>
<td align=center>=</td>
<td align=center> ". $factorial*$i . "</td>
</tr>";
$factorial=$factorial*$i;
echo "<td> ".$factorial. " </td>";
$i++;
} while($i<=numero)
?>
</tbody>
</table>
</div>
</body>
</html>
Note: It does not show the same result, but it does not mark me error