GeekInterview.com
Answered Questions

Sum of two numbers without using arithmetic operators

Asked By: meda_reddy | Asked On: Jul 15th, 2008

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

Star Read Best Answer

Editorial / Best Answer

Answered by: jintojos

View all answers by jintojos

Member Since May-2008 | Answered On : Jul 17th, 2008

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

Answered by: And on: Aug 28th, 2012

For two positive numbers:

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

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

Answered by: mahamad on: Jun 14th, 2012

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5.     int a=20,b=10,c;
  6.     clrscr();
  7.     c=a-~b-1;             //it will change the sign of operator truly magic
  8.     printf("sum is %d",c);
  9.     getch();
  10.     return 0;
  11. }

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: