Hackerrank | 30 days of code | Day 10-Solution in c++| Binary-Numbers-hackerrank-Solution-in-c++
https://www.hackerrank.com/challenges/30-Binary-Numbers/problem
Day 10 Binary Numbers Solution in Cpp.#include <iostream> using namespace std; int main() { int n; cin >> n; int sum = 0; int max = 0; while (n > 0) { if (n % 2 == 1) { sum++; if (sum > max) max = sum; } else sum = 0; n = n / 2; } cout << max; return 0; }
0 Comments