forked from Andyy-18/CPP-BASICS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionHW2.cpp
66 lines (48 loc) · 953 Bytes
/
FunctionHW2.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
// Total no of setbits in two numbers
int setBits(int n){
int count = 0;
while(n != 0){
if(n&1 == 1){
count++;
}
n=n>>1;
}
return count;
}
int main()
{
int a,b;
cout<<"Enter the values of a and b : "<<endl;
cin>>a>>b;
int ans = setBits(a) + setBits(b);
cout<<"Total set bits in a and b is : "<<ans<<endl;
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
int setbits(int a,int b){
int count = 0;
while(a>0 & b>0){
if(a&1 == 1){
count++;
}
a=a>>1;
if(b&1 == 1){
count++;
}
b=b>>1;
}
return count;
}
int main()
{
int a,b;
cout<<"Enter the values of a and b : "<<endl;
cin>>a>>b;
cout<<"Total set bits in a and b is : "<<setbits(a,b)<<endl;
return 0;
}
*/