using System;
namespace example
{
class Program
{
static void Main(string[] args)
{
int num1, num2;
//Take input from user
Console.WriteLine("Enter a Number");
num1=Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter a Number");
num2 = Convert.ToInt16(Console.ReadLine());
int sum = num1 - ~num2 - 1;
Console.WriteLine(sum);
}
}
}
Algorithm:
In Data structure ~ is 1's complement operator. This is equivalent to:
~a = -b + 1
So, a - ~b -1
= a-(-b + 1) + 1
= a + b – 1 + 1
= a + b