Monday, June 21, 2021

Find sum of two number without using any arithmetic operator.

class Program
    {
        static void Main(string[] args)
        {
 
            int a = 10, b = 5;
            if (b > 0)
            {
                while (b > 0)
                {
                    a++;
                    b--;
                }
            }
            // when 'b' is negative
            if (b < 0)
            { 
                while (b < 0)
                {
                    a--;
                    b++;
                }
            }
            Console.Write("Sum is: " + a);
        }
 
    }

No comments:

Post a Comment