how to add two numbers without using arithmetic operators?

Answers were Sorted based on User's Feedback



how to add two numbers without using arithmetic operators?..

Answer / sanjay bhosale

int x=12382,y=2;
int xor, and, temp;
and = x & y;
xor = x ^ y;

while(and != 0 )
{
and <<= 1;
temp = xor ^ and;
and &= xor;
xor = temp;
}
printf(" sum is : %d",xor);

Is This Answer Correct ?    0 Yes 0 No

how to add two numbers without using arithmetic operators?..

Answer / shashishekar

#include<stdio.h>
#include<conio.h>
int main()
{
int a= 10;
int b=5;
int sum=0;
sum= a-(~b)-1;
printf(" sum= %d",sum);
getch();
}

Is This Answer Correct ?    0 Yes 0 No

how to add two numbers without using arithmetic operators?..

Answer / mallikarjun

#include<stdio.h>
#include<conio.h>
main()
{
int a= 10;
int b=5;
sum=0;
sum= a&&b;
printf(" sum= %d",sum);
}

Is This Answer Correct ?    9 Yes 10 No

how to add two numbers without using arithmetic operators?..

Answer / rajkumar

#include<stdio.h>
#include<conio.h>
void main()
{
int a=6,b=3,sum=0;
sum=a^b;
printf("sum=%d",sum);
getch();
}

Is This Answer Correct ?    3 Yes 9 No

Post New Answer

More C Interview Questions

Explain what is wrong with this statement? Myname = ?robin?;

0 Answers  


What is static function in c?

0 Answers  


write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables

2 Answers   TCS,


What are the different types of endless loops?

0 Answers  


How can I prevent another program from modifying part of a file that I am modifying?

0 Answers  






Difference between linking and loading?

0 Answers  


typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

0 Answers   Wilco,


a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

0 Answers  


int main() { int i=1; switch(i) { case '1': printf("hello"); break; case 1: printf("Hi"); break; case 49: printf("Good Morning"); break; } return 0; }

3 Answers  


1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop

2 Answers  


C program to read the integer and calculate sum and average using single dimensional array

0 Answers  


What are the advantages of union?

0 Answers  


Categories