lunes, enero 30, 2017

Vectores en PHP

Formulario que recibe 10 números para ordenarlos con vectores


vectores.php

<!DOCTYPE html>
<html>
<head>
<title>Ordenamiento de vectores</title>
<meta charset="utf-8">
<style type="text/css">
*{
font-size: 1.05em;
}
input:hover{
background-color: rgb(0,100,12);
}
</style>
</head>
<body>
<form action="procesarvector.php" method="post">
<table align="center" width="30%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center" colspan="2">Ingrese 10 numeros</td>
</tr>
<?php
$i=0;
do{
?>
<tr>
<td>Número <?php echo $i;?></td>
<td><input type="text" name=n<?php echo $i;?>>
</tr>
<?php
$i++;
}while($i<=10) ?>
</table>
</form>

</body>
</html>

Ordenamiento de vectores

procesarvector.php
<!DOCTYPE html>
<html>
<head>
<title>Ordenamiento de vectores</title>
<meta charset="utf-8">
<style type="text/css">
*{
font-size: 1.05em;
}
</style>
</head>
<body>
<?php
for ($i=0; $i <10 ; $i++) {
$numeros[$i]=$_POST["n$i"];
}
for ($i=0; $i < 10; $i++) {
echo "Numero $i : ".$numeros[$i]."<br>";
}
for ($i=0; $i < 10; $i++) {
for ($j=0; $j < 10; $j++) {
if($numeros[$i]<$numeros[$j]){
$temp=$numeros[$i];
$numeros[$i]=$numeros[$j];
$numeros[$j]=$temp;
}
}
}
echo "<br>Numeros Ordenados<br>";
for ($i=0; $i < 10; $i++) {
echo "Numero $i : ".$numeros[$i]."<br>";
}
?>
</form>
</body>
</html>

No hay comentarios:

Publicar un comentario