Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Swap numbers without the third variable using the XOR operator
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; namespace Rextester { public class Program { public static void Main(string[] args) { int a = 7, b = 5; Console.WriteLine("*** Swap Number Without Third Variable ***"); Console.WriteLine("Before Swap"); Console.WriteLine("a={0}, b={1}", a, b); Console.WriteLine("Step 1"); a ^= b; Console.WriteLine("a={0}, b={1}", a, b); Console.WriteLine("Step 2"); b ^= a; Console.WriteLine("a={0}, b={1}", a, b); Console.WriteLine("Step 3"); a ^= b; Console.WriteLine("a={0}, b={1}", a, b); Console.WriteLine("After Swap"); Console.WriteLine("a={0}, b={1}", a, b); } } }
run
|
edit
|
history
|
help
1
System Convert
a
LabExer2-RCA
Reference Type parameter by Ref vs. Normal
Namespace addition
HelloWorld
Public access specifier
RegEx
asdfgthyjukjyhtgrfed
Hexagon Tringle