Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Last active January 4, 2024 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lnrsoft/91ebbe51d80d322d7759bc2d13fc1e35 to your computer and use it in GitHub Desktop.
Save lnrsoft/91ebbe51d80d322d7759bc2d13fc1e35 to your computer and use it in GitHub Desktop.
Binary Numbers.cpp
#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