jueves, 12 de diciembre de 2019

codigo javascript fibonacci

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <script>
            function fibonacci() {
                var n = document.getElementById('numero').value;
                var a = 0;
                var b = 1;
                var aux = "";
                for (i = 1; i <= n; i++) {
                    var numeroTemporal = a;
                    a = b;
                    b = numeroTemporal + b;
                    aux+=" "+a;
                   //document.write(" "+a);
                }



                document.getElementById('respuesta').value=aux+"";
            }

        </script>

        <input type="text" id="numero"><br><br>
        <input type="submit" onclick="fibonacci()" value="calcular"><br><br>
        <input type="text" id="respuesta">
    </body>
</html>

No hay comentarios.:

Publicar un comentario