Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 518d699

Browse files
program to count number fo consecutive ones
1 parent c3085cf commit 518d699

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /