Social Icons

Wednesday, 12 February 2014

Program to interchange 2 variables value without using the third variable

using System;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            Console.Write("\n Enter first number : ");
            a = int.Parse(Console.ReadLine());
            Console.Write("\n Enter second number : ");
            b = int.Parse(Console.ReadLine());

            a = a + b;
            b = a - b;
            a = a - b;

            Console.WriteLine("\n\n\tNumbers after interchange\n ");
            Console.WriteLine("\n First no is : " + a);
            Console.WriteLine("\n Second no is : " + b);

            Console.ReadLine();
        }
    }
}

                                                       Output

No comments:

Post a Comment