File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Hackerrank solutions/30 days Of Code Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments