Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How to add 2 numbers without + sign?
I have given you some examples.Which add 2 numbers with using + sign.
 
Using recursion:

#include <stdio.h>

int add(int m, int n)
{
  if (!m) 
  return n;
  else
  return add((m & n) << 1, m ^ n);
}
int main()
{
   int m,n;
   printf("Enter the 2 numbers: 
");
   scanf("%d",&m); 
   scanf("%d",&n);
   printf("Addition is: %d",add(m,n));
}
m ^ n is mandatry in addition of bits, "(a & b) << 1" is the overflow. 

Using Binary operator:
1 = 001
2 = 010
add(001, 010) => a -> 001, b-> 010
=011
Posted By: Name:Rajesh Kr URL: How to add 2 numbers without + sign?