-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram32.cpp
More file actions
49 lines (35 loc) · 908 Bytes
/
program32.cpp
File metadata and controls
49 lines (35 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Sum of two numbers without using arithmetic operators(I SOLVED THIS PROBLEM BY THREE DIFFERENT METHODS )
#include<iostream>
using namespace std;
void usingOR(int a,int b){
int sum = a | b;
cout<<"Sum is "<<sum<<endl;
}
int sumtwo (int a,int b){
int carry = b,sum ;
while(carry != 0){
sum = a^b;
carry = (a&b)<<1;
a = sum;
b = carry;
}
return sum;
}
int main(){
int a,b;
cout<<"Enter first number : ";
cin>>a;
cout<<"Enter second number : ";
cin>>b;
// THIS IS THE BRUTEFORCE METHOD
// for(int i = 1;i<=b;i++){
// a++;
// }
// cout<<"Sum of these two numbers : "<<a<<endl;
// THIS IS DONE WITH THE HELP OF & and ^ operators
// int result = sumtwo(a,b);
// cout<<"Sum of these two numbers : "<<result<<endl;
//THIS IS DONE WITH THE HELP OF |
usingOR(a,b);
return 0;
}