0
Write a code in c++ to print sum of two numbers without using arthematic operator
3 ответов
+ 2
@Nandu using ++ and -- counts as using arithmetic operators.
+ 2
You could also use recursion:
int add(int a, int b) {
if(b==0)
return a;
else
return add(a ^ b, (a & b) << 1);
}
+ 1
#include <iostream>
using namespace std;
int add(int a, int b) {
while(b != 0) {
int c = a & b;
a = a ^ b;
b = c << 1;
}
return a;
}
int main() {
int a = 3, b = 5;
cout << add(a, b);
return 0;
}