Skip to content

Commit 6f47f76

Browse files
authored
Merge pull request #4 from abhi7187/patch-1
Add two binary
2 parents f2800f6 + 94019c1 commit 6f47f76

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Addtwobinary.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<iostream>
2+
#include<math.h>
3+
using namespace std;
4+
void addbinary(int a,int b){
5+
int s=a+b;
6+
int bit,y=0,i=0;
7+
while(s>0){
8+
int bit=s&1;
9+
y=bit*pow(10,i)+y;
10+
s=s>>1;
11+
i++;
12+
}
13+
cout<<"sum of binary is :-"<<y;
14+
}
15+
int main(){
16+
int a,b,i=0,j=0,r,r1,a1=0,b1=0;
17+
cout<<"Enter the first binary\n";
18+
cin>>a;
19+
cout<<"Enter 2nd binary\n";
20+
cin>>b;
21+
while(a>0){
22+
r=a%10;
23+
a1=a1+r*pow(2,i);
24+
a/=10;
25+
i++;
26+
}
27+
while(b>0){
28+
r1=b%10;
29+
b1=b1+r1*pow(2,j);
30+
b/=10;
31+
j++;
32+
}
33+
addbinary(a1,b1);
34+
35+
}

0 commit comments

Comments
 (0)