R Lang

R Program to swap two numbers without using third variable1 min read

In this program, You will learn how to swap two numbers without using third variable in R.

R Program Example: How to swap two numbers without using third variable in R




Output:

The code first reads in values for x and y from the user and stores them as integers. It then swaps the values of x and y using a simple algorithm.

First, it adds x and y and stores the result in x. Then it subtracts y from the new value of x and stores the result in y. Finally, it subtracts the new value of y from the original value of x and stores the result in x.

After the values have been swapped, the code prints the new values of x and y to the console.

Leave a Comment