Thursday, December 31, 2015
C program to add 2 numbers without using arithmetic operators
#include <stdio.h>
int main(void) {
int a = 3, b = 5, c = 0;
while(b != 0){
c = a & b; // carry
a = a ^ b;
b = c << 1;
}
printf("%d",a);
return 0;
}
Ref: http://www.geeksforgeeks.org/add-two-numbers-without-using-arithmetic-operators/
Subscribe to:
Post Comments (Atom)
Great!!! Was looking for this logic for long time. Thanks for sharing.
ReplyDeleteCheers,
http://www.flowerbrackets.com/addition-operation-bitwise-operators-java/