Write a script to Swap 2 numbers without a temporary variable

In computer programming, the act of swapping two variables refers to mutually exchanging the values of the variables. Usually, this is done with the data in memory.In this Program we were Swapping two numbers. Swap means we are interchanging two numbers.

 Example in above code we are taking value of a =8 and Value of b= 5. Before Swapping a=5 and b=8, after Swapping a=5and b=8
 We can write swapping code in two ways
i)    By using a temporary  Variable
ii)    Without using temporary Variable.
By using temporary Variable in this we can use one extra variable to store the value of A or B. In that case VB Script program will be as shown:-

Out Put Of the Above Program








Now we write a Script without using third variable(temporary) variable. In this case VB Script program will be as shown:

Out Put Of the Above Program








No comments:

Post a Comment