We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, June 17, 2015

Write a program swapping two numbers without using third variable



class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            Console.WriteLine("Enter the first number");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the second number");
            b = int.Parse(Console.ReadLine());
            a = a + b;
            b = a - b;
            a = a - b;

            Console.WriteLine("After swaping");
            Console.WriteLine("The first number is:{0}", a);
            Console.WriteLine("The second number is:{0}", b);

            Console.ReadLine();

        }


    }
output:

No comments: