Last active
January 4, 2024 21:40
-
-
Save lnrsoft/91ebbe51d80d322d7759bc2d13fc1e35 to your computer and use it in GitHub Desktop.
Binary Numbers.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main() { | |
int n; | |
int reminder = 0; | |
int count = 0; | |
int max = 0; | |
cin >> n; | |
while (n != 0) { | |
reminder = n % 2; | |
n = n / 2; | |
if (reminder == 1) { | |
count++; | |
} else { | |
count = 0; | |
} | |
if (count > max) { | |
max = count; | |
} | |
} | |
cout << max; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment