Nombre:
Alexandra Maguana
Ciclo: Quinto
“Sistemas”HTML
<head>
<style> type= "text/CSS">
[required]{
borde-color:red;
box-shadow:0px 0px 5px green;
}
</style>
</head>
<body>
<form action ="Resul.php" method ="POST">
<table border=2>
<tr>
<td><input type="integer" name="num" required style="width:340px;height:30px"> </td>
</tr>
<td> <input name="4" type="submit" value="Ingresar" >
</tr>
</table>
</form>
</body>
</html>
PHP
<?php$num=$_POST['num'];
echo"<table borde=2><form action='Prueba.php' method='POST'>";
For($i=1;$i<=$num;$i++){
echo"<tr><td>num</td>";
echo"<td><input type='text'" ." name='num$i'"." required/></td>";
echo "</tr>";
}
echo "</table>";
$boton1 = "<input name='b1' type=\"submit\" Value=\"Suma"."\">";
echo $boton1;
$boton2 = "<input name='b2' type=\"submit\" Value=\"Promedio"."\">";
echo $boton2;
$boton3 = "<input name='b3' type=\"submit\" Value=\"Promedio Pares"."\">";
echo $boton3;
$boton4 = "<input name='b4' type=\"submit\" Value=\"Promedio Impares"."\"></form>";
echo $boton4;
?>
PHP
<?php$x=0;
if (isset($_POST['b1']))
$x=1;
if (isset($_POST['b2']))
$x=2;
if (isset($_POST['b3']))
$x=3;
if (isset($_POST['b4']))
$x=4;
switch($x){
case 1:
$acu=0;
for($i=1;$i<count($_POST);$i++){
$acu+=$_POST['num'.$i];
}
echo $acu;
break;
case 2:
$acu=0;
for($i=1;$i<count($_POST);$i++){
$acu+=$_POST['num'.$i];
}
echo $acu/(count($_POST)-1);
break;
case 3:
$par=0;
$con=0;
for($i=1;$i<count($_POST);$i++){
if (($_POST['num'.$i]%2)==0){
$par+=$_POST['num'.$i];
$con++;
}
}
echo $par/$con;
break;
case 4:
$impar=0;
$con=0;
for($i=1;$i<count($_POST);$i++){
if (($_POST['num'.$i]%2)!=0){
$impar+=$_POST['num'.$i];
$con++;
}
}
echo $impar/$con;
break;
}
?>
EJECUCION
Al ejecutar con el servidor localhost nos parece la siguiente ventana.
Ingresamos la cantidad de numeros que deseamos ingresar y hacemos clic en el boton Ingresar.
Ingresamos los numeros que deseamos.
Selecionamos las opciones que nos parece:
Al seleccionar Suma nos muestra la suma de todos los numeros que ingresamos.
Al seleccionar Promedio nos muestra el de todos los numeros que ingresamos.
Al seleccionar Promedio Pares nos muestra el promedio de todos los numeros pares que ingresamos.
Al seleccionar Promedio Impares nos muestra el promedio de todos los numeros impares que ingresamos.
No hay comentarios:
Publicar un comentario