Thursday, October 29, 2015

Swapping of Two Numbers in JavaScript

This sample program will ask the user to enter two numbers and then our program will enter change the arrangement of two numbers.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head>
  <title>Swapping of Numbers</title>
</head>
<style>
h3 {
   font-family:arial;
   };
</style>
<body>
  <script>
    
var val_1 = parseInt(prompt("Enter First Value : "));
var val_2 = parseInt(prompt("Enter Second Value : "));
    var temp=0;
document.write("<h3> Swapping of Numbers</h3>");
document.write("<h3> BEFORE SWAPPING </h3>");
document.write("<font face='arial' size='3'>");
    document.write(" First Value    : " + val_1 + ".</font><br>");
document.write("<font face='arial' size='3'>");
    document.write(" Second Value   : " + val_2 + ".</font><br>");
 
temp = val_1;
     val_1 = val_2;
     val_2 = temp;
               
    document.write("<h3> AFTER SWAPPING</h3>");
document.write("<font face='arial' size='3'>");
    document.write(" First Value      : " + val_1 + ".</font><br>");
document.write("<font face='arial' size='3'>");
    document.write(" Second Value     : " + val_2 + ".</font><br>");

document.write("<h3> End of Program </h3>");
</script>
</body>
</html>

No comments:

Post a Comment