We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c3085cf commit 518d699Copy full SHA for 518d699
Bit Manipulation/CountConsecutiveOnes.cpp
@@ -0,0 +1,26 @@
1
+#include<iostream>
2
+
3
4
+using namespace std;
5
6
+/*Program to count number of consecutive ones using left shifting the number until it becomes 0
7
+*/
8
9
+int countConsecutiveOnes(int n){
10
11
+ int count=0;
12
+ while(n)
13
+ {
14
+ n &= n << 1;
15
+ count++;
16
+ }
17
18
+ return count;
19
+}
20
21
22
+int main()
23
+{
24
+ cout<<countConsecutiveOnes(15);
25
+ return 0;
26
0 commit comments