Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- int a = 5;
- int b = 9;
- // using temporary variable
- int temp = a;
- a = b;
- b = temp;
- Console.WriteLine("a = " + a);
- Console.WriteLine("b = " + b);
- Console.WriteLine();
- // using xor swap
- // negative numbers lose their sign
- int x = 5;
- int y = 9;
- x ^= y;
- y ^= x;
- x ^= y;
- Console.WriteLine("x = " + x);
- Console.WriteLine("y = " + y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement