Swapping four variables without temporary variable | C # program to swap 4 variables without using temporary variable . ; swapping a and b variables ; swapping b and c variables ; swapping c and d variables ; Driver Code ; initialising variables ; Function call
using System ; class GFG { static void swap ( int a , int b , int c , int d ) { a = a + b ; b = a - b ; a = a - b ; b = b + c ; c = b - c ; b = b - c ; c = c + d ; d = c - d ; c = c - d ; Console . WriteLine ( " values ▁ after ▁ " + " swapping ▁ are ▁ : ▁ " ) ; Console . WriteLine ( " a ▁ = ▁ " + a ) ; Console . WriteLine ( " b ▁ = ▁ " + b ) ; Console . WriteLine ( " c ▁ = ▁ " + c ) ; Console . WriteLine ( " d ▁ = ▁ " + d ) ; } public static void Main ( ) { int a = 1 ; int b = 2 ; int c = 3 ; int d = 4 ; Console . WriteLine ( " values ▁ before ▁ " + " swapping ▁ are ▁ : ▁ " ) ; Console . WriteLine ( " a ▁ = ▁ " + a ) ; Console . WriteLine ( " b ▁ = ▁ " + b ) ; Console . WriteLine ( " c ▁ = ▁ " + c ) ; Console . WriteLine ( " d ▁ = ▁ " + d ) ; Console . WriteLine ( " " ) ; swap ( a , b , c , d ) ; } }