Logic to swap two numbers without using third variable

// Logic one

            a = a + b; // 77 = 32 + 45

            b = a - b; // 32 = 77 - 45

            a = a - b; // 45 = 77 - 32

 // Logic Two

            a = a * b; // 1440 = 32 * 45

            b = a / b; // 32 = 1440 / 45

            a = a / b; // 45 = 1440 / 32



Comments

Popular posts from this blog

String class in C# (Methods and properties)

SQL Server Queries

Simple calculator (Console application/Java)