美文网首页
Day24作业

Day24作业

作者: 周zau1 | 来源:发表于2018-08-20 23:06 被阅读52次
    第十题未做
    <!--
        1、判断一个数是奇数还是偶数
        2、给一个年份,判断是否是闰年
        3、给一个数n,计算n的阶乘
        4、打印99乘法表
        5、计算1-1/2+1/3-1/4 …  1/100的和
        6、给一个n,求1!+2!+3!+4!+5!...+n!
        7、找到所有的水仙花数
        8、输入三个数,找到其中最大的,用一句话写出来
        9、给一个数组,找到其中最大值和最小值
        10、用while打印十行十列表格,表格里面写1-100,并且隔行变色
        11、自己实现随机  a, b 之间的整型
    -->
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title></title>
            <script type="text/javascript" src="js/1.js"></script>
        </head>
        <body>
            <p>1、判断一个数是奇数还是偶数</p>
            <input type="text" name="a1" id="a1" value="" placeholder="请输入一个整数"/>
            <button onclick="one()">确定</button>
            
            <p>2、给一个年份,判断是否是闰年</p>
            <input type="text" name="a2" id="a2" value="" placeholder="请输入年份(如2018)"/>
            <button onclick="two()">确定</button>
            
            <p>3、给一个数n,计算n的阶乘</p>
            <input type="text" name="a3" id="a3" value="" placeholder="请输入一个整数"/>
            <button onclick="three()">确定</button>
            
            <p>4、打印99乘法表</p>
            <button onclick="four()">显示九九乘法表</button>
            
            <p>5、计算1-1/2+1/3-1/4 …  1/100的和</p>
            <button onclick="five()">显示结果</button>
            
            <p>6、给一个n,求1!+2!+3!+4!+5!...+n!</p>
            <input type="text" name="a6" id="a6" value="" placeholder="请输入一个数字"/>
            <button onclick="six()">确定</button>
            
            <p>7、找到所有的水仙花数</p>
            <button onclick="seven()">显示所有水仙花数</button>
            
            <p>8、输入三个数,找到其中最大的,用一句话写出来</p>
            <input type="text" name="a6" id="a71" value="" placeholder="请输入第一个数字"/>
            <input type="text" name="a6" id="a72" value="" placeholder="请输入第二个数字"/>
            <input type="text" name="a6" id="a73" value="" placeholder="请输入第三个数字"/>
            <button onclick="eight()">显示最大值</button>
            
            <p>9、给一个数组,找到其中最大值和最小值</p>
            <input type="text" name="" id="a9" value="" placeholder="请输入一个数组"/>
            <button onclick="nine()">显示结果</button>
            
            <!--<p>10、用while打印十行十列表格,表格里面写1-100,并且隔行变色</p>
            <table border="" cellspacing="0" cellpadding="" width="100%">
                
                <tr><td>Header</td></tr>
                <tr><td>Data</td></tr>
            </table>-->
            
            <p>11、自己实现随机  a, b 之间的整型</p>
            <input type="text" name="" id="a111" value="" placeholder="请输入第一个数"/>
            <input type="text" name="" id="a112" value="" placeholder="请输入第二个数"/>
            <button onclick="eleven()">Roll it!!</button>
            
        </body>
    </htm
    
    function one(){
        var x = document.getElementById('a1').value
        if (x % 2 == 0){
            alert(x + '是偶数')
        } else if(x % 2 == 1){
            alert(x + '是奇数')
        } else{
            alert('输入的不是整数,请重新输入!')
        }
    }
    
    function two(){
        var x = document.getElementById('a2').value
        if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0){
            alert('公元' + x + '年是闰年')
        } else{
            alert('公元' + x + '年不是闰年')
        }
    }
    
    function three(){
        var x = document.getElementById('a3').value
        m = 1
        for (n=1;n<=x;n++){
            m *= n
        } alert(x + '的阶乘为' + m)
    }
    
    function four(){
        var str = ''
        for (a=1;a<=9;a++){
            for (b=a;b<=9;b++){
                str += a+'*'+b+'='+a*b+' '
                if (b == 9){
                    str += '\n'
                }
            }
        } alert(str)
    }
    
    function five(){
        var m = 0
        for (n=2;n<101;n++){
            if (n % 2 == 0){
                m += 1/n
            }
            else{
                m -= 1/n
            }
        }alert(1-m)
    }
    
    function six(){
        var x = document.getElementById('a6').value
        sum = 0
        for (m=1;m<=x;m++){
            product = 1
            for (n=1;n<=m;n++){
                product *= n        
            }sum += product
        }alert('和为'+sum)
    }
    
    function seven(){
        str = ''
        for (i=100;i<1001;i++){
            n = String(i)
            if (n[0]**3 + n[1]**3 + n[2]**3 == n){
                str += n + '\n'
            }
        }alert(str)
    }
    
    function eight(){
        alert('最大值是' + Math.max(document.getElementById('a71').value,document.getElementById('a72').value,document.getElementById('a73').value))
    }
    
    function nine(){
        var str = document.getElementById('a9').value
        var num = String(str.split(','))
        alert(num)
        max_n = parseInt(num[0])
        min_n = parseInt(num[0])
        for (i=0;i<num.length;i++){
            parseInt(num[i])
            if (num[i]>max_n){
                max_n = num[i]
            }else if (num[i]<min_n){
                min_n = num[i]
            }
        }alert('最大值为:'+max_n+' 最小值为:'+min_n)
        
    }
    
    function eleven(){
        var a = document.getElementById('a111').value
        var b = document.getElementById('a112').value
        var c = Math.abs(a-b)
        percent = 1/c
        rand = Math.random()
        num = Math.round(rand / percent)
        if (a>b){
            alert(num + parseInt(b))
        }else{
            alert(num + parseInt(a))
        }
        
    }
    

    相关文章

      网友评论

          本文标题:Day24作业

          本文链接:https://www.haomeiwen.com/subject/lpmriftx.html