-
Lenguaje
PHP
-
Descripción
Se requiere utilizar una calculadora que pueda realizar operaciones básicas como lo son: suma, resta, multiplicación, división o residuo, para esto se reciben 3 números, el primer número representa al valor 1, el segundo el valor 2 y el último represente la opción del usuario; se deberá mostrar el resultado final de la operación así como la opción elegida.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Suma, resta, multiplicación, división o residuo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
<html>
<head>
<title>Suma, resta, multiplicación, división o residuo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
if ($_SERVER['REQUEST_METHOD']=='POST')
{
$a = intval ($_POST['a']);
$b = intval ($_POST['b']);
$operacion = intval ($_POST['operacion']);
$resultado_final=0;
if($operacion==1)
{
$resultado_final=$a+$b;
echo 'Suma<br>'
}
if($operacion==2)
{
$resultado_final=$a-$b;
echo 'Resta<br>'
}
if($operacion==3)
{
$resultado_final=$a*$b;
echo 'Multiplicación<br>'
}
if($operacion==4&&$b==0)
echo 'No se puede obtener la división<br>'
if($operacion==4&&$b!=0)
{
$resultado_final=$a/$b;
echo 'División<br>'
}
if($operacion==5&&$b==0)
echo 'No se puede obtener el residuo<br>'
if($operacion==5&&$b!=0)
{
$resultado_final=$a%$b;
echo 'Residuo<br>'
}
echo 'Valor de resultado final: ' . $resultado_final . "<br/>\n";
}
<form method="post">
<table style="text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<td>
<label for="a">Ingresa el valor de a:</label>
</td>
<td>
<input name="a" required="required" step="1" type="number" />
</td>
</tr>
<tr>
<td>
<label for="b">Ingresa el valor de b:</label>
</td>
<td>
<input name="b" required="required" step="1" type="number" />
</td>
</tr>
<tr>
<td>
<label for="operacion">Selecciona el valor de operacion:</label>
</td>
<td>
<select name="operacion" required="required">
<option value="1">Suma</option>
<option value="2">Resta</option>
<option value="3">Multiplicación</option>
<option value="4">División</option>
<option value="5">Residuo</option>
</select>
</td>
</tr>
<tr align="center">
<td colspan="2" rowspan="1">
<input value="Procesar" type="submit" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<table style="text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<td>
<label for="a">Ingresa el valor de a:</label>
</td>
<td>
<input name="a" required="required" step="1" type="number" />
</td>
</tr>
<tr>
<td>
<label for="b">Ingresa el valor de b:</label>
</td>
<td>
<input name="b" required="required" step="1" type="number" />
</td>
</tr>
<tr>
<td>
<label for="operacion">Selecciona el valor de operacion:</label>
</td>
<td>
<select name="operacion" required="required">
<option value="1">Suma</option>
<option value="2">Resta</option>
<option value="3">Multiplicación</option>
<option value="4">División</option>
<option value="5">Residuo</option>
</select>
</td>
</tr>
<tr align="center">
<td colspan="2" rowspan="1">
<input value="Procesar" type="submit" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>