Monday, September 10, 2012

Write c# method to swap 2 numbers without using the third/temp variable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace swap
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 30;
            a = a + b;
            b = a - b;
            Console.WriteLine("the value of b:" + b);
            a = a - b;
            Console.WriteLine(a);
        }
    }
}

No comments:

Post a Comment