Skip to content

Commit 610c68e

Browse files
authored
Create Day10-BinaryNumbers.c
1 parent 97df875 commit 610c68e

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Sample Input 1
3+
4+
5
5+
Sample Output 1
6+
7+
1
8+
Sample Input 2
9+
10+
13
11+
Sample Output 2
12+
13+
2
14+
15+
16+
Input Format
17+
18+
A single integer,n .
19+
20+
Output Format
21+
22+
Print a single base-10 integer that denotes the maximum number of consecutive 1's in the binary representation of n. */
23+
24+
25+
#include <assert.h>
26+
#include <limits.h>
27+
#include <math.h>
28+
#include <stdbool.h>
29+
#include <stddef.h>
30+
#include <stdint.h>
31+
#include <stdio.h>
32+
#include <stdlib.h>
33+
#include <string.h>
34+
35+
int main()
36+
{
37+
int n;
38+
scanf("%d",&n);
39+
40+
int rem = 0;
41+
int curr = 0;
42+
int max = 0;
43+
44+
45+
while(n > 0) {
46+
rem = n % 2;
47+
if(rem == 1) {
48+
curr++;
49+
if(curr >= max) {
50+
max = curr;
51+
}
52+
} else {
53+
curr = 0;
54+
}
55+
n = n / 2;
56+
}
57+
58+
printf("%d\n", max);
59+
60+
return 0;
61+
}

0 commit comments

Comments
 (0)