-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 10: Binary Numbers
53 lines (44 loc) · 970 Bytes
/
Day 10: Binary Numbers
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
#include <bits/stdc++.h>
using namespace std;
int globalcount=0;
void decToBinary(int n)
{
// array to store binary number
int binaryNum[32];
int binaryNumb[32];
// counter for binary array
int i = 0;
while (n > 0) {
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
int k=0;
// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--)
{
binaryNumb[k++]=binaryNum[j];
// cout<<binaryNum[j];
}
int count=0;
for(int p=0;p<=k;p++)
{
if(binaryNumb[p]==0)
{
if(globalcount<count){globalcount=count;}
count=0;
continue;
}
count++;
}
cout<<globalcount;
}
int main()
{
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
decToBinary(n);
return 0;
}