//To add two numbers without using "+" plus sign
#include <stdio.h>
int add(int a, int b){
int sum, carry;
sum = a ^ b;
carry = a & b;
while (carry != 0){
carry <<= 1;
a = sum;
b = carry;
sum = a ^ b;
carry = a & b;
}
return sum;
}
void main(){
int answer = add(2,5);
printf("%d\n", answer);
}
No comments:
Post a Comment