Sum of two numbers without using arithmetic operators

Ex:
int a=10;
int b=10;
int sum=a+b;
without using "+" operator calculate sum

Questions by meda_reddy

Editorial / Best Answer

jintojos  

  • Member Since May-2008 | Jul 17th, 2008


void main()
 {
          int a=10,b=20;
          while(b--) a++;
           printf("Sum is :%d",a);  
 }

Showing Answers 1 - 19 of 19 Answers

ceren6

  • Jul 18th, 2008
 

#include
int main()
{
unsigned int t = 0xffffffff;
unsigned int z = 1;
int a = 10, b = 10, sum = 0, r = 0;
while (t) {
int t1, t2;
t1 = a & 0x00000001;
t2 = b & 0x00000001;
if ((t1 ^ t2 ^ r) == 1) {
if (t1 == 1 && t2 == 1 && r == 1)
r = 1;
else
r = 0;
sum = sum | z;
} else {
if (t1 == 0 && t2 == 0 && r == 0)
r = 0;
else
r = 1;
}
a >>= 1;
b >>= 1;
z <<= 1;
t >>= 1;
}
printf("sum: %dn", sum);
return 0;
}

  Was this answer useful?  Yes

ceren6

  • Jul 21st, 2008
 

Arithmetic operators
Operator NameSyntaxOverloadableIncluded in C
Unary Plus +a Yes Yes
Addition (Sum) a + b Yes Yes
Prefix Increment ++a Yes Yes
Postfix Increment a++ Yes Yes
Assignment by Addition a += b Yes Yes
Unary Minus (Negation) -a Yes Yes
Subtraction (Difference) a - b Yes Yes
Prefix Decrement --a Yes Yes
Postfix Decrement a-- Yes Yes
Assignment by Subtraction a -= b Yes Yes
Multiplication (Product) a * b Yes Yes
Assignment by Multiplication a *= b Yes Yes
Division (Quotient) a / b Yes Yes
Assignment by Division a /= b Yes Yes
Modulus (Remainder) a % b Yes Yes
Assignment by Modulus a %= b Yes Yes

luckypavan

  • Oct 1st, 2010
 

Code
  1. #include<stdio.h>

  2. "n Please enter a,b values:");

  3.     scanf("%d %d"// using minus operator

  4.     }

  5.     d = square(b) - square(a);  // using square function and - minus operator

  6.     sum = d / c;                // using division operator"The sum of a and b is:%d"

  Was this answer useful?  Yes

sravan

  • Aug 20th, 2011
 

Code
  1.          #include<iostream.h>

  Was this answer useful?  Yes

mukesh kumar

  • Mar 25th, 2012
 

Code
  1. span style="color: #ff0000;">"Enter the two numbers:

  2. ");

  3.  

  4. scanf("%d",&a);

  5. scanf("%d""Sum is: %d",add(a,b));

  6. }

  Was this answer useful?  Yes

mahamad

  • Jun 14th, 2012
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. //it will change the sign of operator truly magic"sum is %d"

  Was this answer useful?  Yes

And

  • Aug 28th, 2012
 

For two positive numbers:

int main(){
int a = 10;
int b = 10;

printf("%d",a ^ b | ((a & b)<< 1));
return 0;
}

  Was this answer useful?  Yes

mukesh

  • Aug 10th, 2015
 

Simple

Code
  1. span style="color: #ff0000;">"%d",c)

  2.  

  3. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions