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, January 13, 2016

Write a program how do we add two numbers without using + operator in C#

class Loop
    {
        public static int Add(int num1, int num2)
        {
            if (num2 == 0)
                return num1;
            return Add(num1 ^ num2, (num1 & num2) << 1);
        }
        static void Main()
        {
            Console.WriteLine(Add(12, 9));
            Console.ReadLine();
        }
    }


Output:
21

No comments: