# Swap two numbers without using third variable

## Problem Statement:-  Program to Swap two numbers without using a third variable using functions.

#### Sample Input/Output:-

 Sample Input First:47 Sample Output First: 74 Sample Input Second: 123255 Sample Output Second: 255123

#### Data requirement:-

Input Data:- num1, num2

Output Data:-num1, num2

Program in C

Code:

Program in C++

## Here is the source code of the C++ Program to Swap two numbers without using a third variable using function.

Code:

### ``import java.util.Scanner;public class SwapTwoNumbersWithoutThird {    /* This function swap two numbers without using third variable */    static void SwapTwoNumbers(int num1, int num2) {        num1 = num1 + num2;        num2 = num1 - num2;        num1 = num1 - num2;        System.out.println("***After Swapping***");        System.out.println("Number 1:" + num1 + "\nNumber 2:" + num2);    }    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        /* Get the input of two variables */        System.out.println("Enter the 1st Number:");        int num1 = sc.nextInt();        System.out.println("Enter the 2nd Number:");        int num2 = sc.nextInt();        /* Call Function SwapTwoNumbers with two Parameters */        SwapTwoNumbers(num1, num2);        sc.close();    }}``Input/Output:Enter the 1st Number:52Enter the 2nd Number:78***After Swapping***Number 1:78Number 2:52

Program in Python

Code: