Answers for "How do you swap two integers without using a temporary variable?"

1

swap of two numbers without using third variable

a=20;
b=40;
a=a+b;  
b=a-b;
a=a-b;
Posted by: Guest on October-20-2021
4

swap 2 numbers without using 3rd variable

a=10;
b=20;
a=a+b;//a=30 (10+20)    
b=a-b;//b=10 (30-20)    
a=a-b;//a=20 (30-10)
Posted by: Guest on May-16-2021
1

swap two variables without temporary java

import java.*; 
  
class noTemp { 
  
    public static void main(String a[]) 
    { 
        int x = 10; 
        int y = 5; 
        x = x + y; 
        y = x - y; 
        x = x - y; 
        System.out.println("After swaping:"
                           + " x = " + x + ", y = " + y); 
    } 
}
Posted by: Guest on January-22-2021
0

swap 2 integers without using temporary variable

using System;

class MainClass {
  public static void Main (string[] args) {
    int num1 = int.Parse(Console.ReadLine());
    int num2 = int.Parse(Console.ReadLine());
      num1 = num1 + num2; 
      num2 = num1 - num2; 
      num1 = num1 - num2; 
      Console.WriteLine("After swapping: num1 = "+ num1 + ", num2 = " + num2); 
    Console.ReadLine();
  }
}
Posted by: Guest on September-23-2020
2

how to swap 2 numbers without 3rd variable

int a = 3;
int b = 5;
a = b*a;
b = a/b
a = a/b
Posted by: Guest on April-02-2021
0

swap two numbers without using third variable

var a=window.prompt('enter a number')var b=window.prompt('enter a number')var a=a+b;var b=a-b;var a=a-b;console.log ("value of a is",a);console.log('value of b is',b);
Posted by: Guest on June-28-2021

Code answers related to "How do you swap two integers without using a temporary variable?"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language