• Lenguaje

    PHP

  • Descripción

    Realizar un programa que pida el ingreso de un número, el número debe estar en el rango -1000 a 1000. Se pide determinar la cantidad de dígitos del número ingresado y además determinar si el número es positivo, negativo o cero.

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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Positivo, negativo o cero</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
<?php

if ($_SERVER['REQUEST_METHOD']=='POST')
{
    $un_numero = intval ($_POST['un_numero']);
    $cantidad_de_digitos=0;
    if($un_numero<-1000||$un_numero>1000)
        echo 'Fuera de rango<br>'
    if($un_numero>=-1000&&$un_numero<=1000&&$un_numero<0)
    {
        echo 'Negativo<br>'
        $cantidad_de_digitos=1+floor(log(-$un_numero)/log(10));
    }
    if($un_numero>=-1000&&$un_numero<=1000&&$un_numero==0)
        echo 'Cero<br>'
    if($un_numero>=-1000&&$un_numero<=1000&&$un_numero>0)
    {
        echo 'Positivo<br>'
        $cantidad_de_digitos=1+floor(log($un_numero)/log(10));
    }
    echo 'Valor de cantidad de digitos: ' . $cantidad_de_digitos . "<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="un_numero">Ingresa el valor de un numero:</label>
                        </td>
                        <td>
                            <input name="un_numero" required="required" step="1" type="number" />
                        </td>
                    </tr>
                    <tr align="center">
                        <td colspan="2" rowspan="1">
                            <input value="Procesar" type="submit" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>