Computer Science, asked by chandasumana458, 19 hours ago

Write a function prototype which is used to swap the values of two memory locations without a third variable. Ex- input - int a=3, b=5 [1] Output --- a=5, b=3। ​

Attachments:

Answers

Answered by Aravinthan31
0

Answer:

import java.util.*;  

class Swap    

{  

   public static void main(String a[])    

   {    

       System.out.println("Enter the value of x and y");  

       Scanner sc = new Scanner(System.in);  

       int x = sc.nextInt();  

       int y = sc.nextInt();  

       System.out.println("before swapping numbers: "+x +" "+ y);  

     

       x = x + y;    

       y = x - y;    

       x = x - y;    

       System.out.println("After swapping: "+x +"  " + y);    

   }    

}  

Explanation:

ALGO:

STEP 1: START

STEP 2: ENTER x, y

STEP 3: PRINT x, y

STEP 4: x = x + y

STEP 5: y= x - y

STEP 6: x =x - y

STEP 7: PRINT x, y

STEP 8: END

MARK AS BRAINLIEST IF U FIND THE ANSWER USEFUL

Similar questions