This program is used to swap two numbers without using temporary variable.
using System;
namespace Swaping
{
class Program
{
static void swap(ref int a,ref int b)
{
a = a + b;
b = a - b;
a = a - b;
}
static void Main(string[] args)
{
int i = 10;
int j = 33;
Console.WriteLine("Before swapping:i={0},j={1}",i,j);
swap(ref i,ref j);
Console.WriteLine("after swapping:i={0},j={1}",i,j);
}
}
}
Thats an interesting Post...
ReplyDeleteCheck out more programs related to c,c++,C# and many more at www.cfetch.blogspot.com
http://www.cfetch.blogspot.com
Delete