write a javscript program to reverse of the number.

In this javascript tutorial we are learning code about reverse of numbers using javascript language.

Reverse of number

  • Integer will become integer.                                                              123456 become 654321 & not 123456.00. 

  • Negative number remains negative only after the reverse.                 ex -1-2-3-4 becomes -4-3-2-1.

  • Any leading zero is been remove after reverse the number. ex 00123 is becomes 321 & not 32100

  • reverse function can accept float and integers.                                   Ex 123.456 is become 654.321  


write a javscript program to reverse of the number.

<html>

<head>

    <title>reverse of number</title>

    </head>

    <script type="text/javascript">

    function rev_num()

        {

    var num=prompt("enter nmber:"," ");

        var n=num;

        var rev=0,rem;

        while(n>0)

            {

                rem=n%10;

                rev=rev*10+rem;

                n=parseInt(n/10);

            }

        document.write("the given nummber is :"+num+"<br/> the reverse number is:"+rev+"\n");

        }

    </script>

    <body align="center" style="font-size:30px" onload="rev_num()">

        <!-- When the page gets loaded rev-num() function gets called-->

    </body>

    

</html>



output:
write a javscript program to reverse of the number.

write a javscript program to reverse of the number.

























Post a Comment

0 Comments