We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 10: Binary Numbers
Day 10: Binary Numbers
Sort by
recency
|
2828 Discussions
|
Please Login in order to post a comment
Java
JS:
c++: ` void d_b{int n){ int max= 0, count =0, rem =0; if (n == 0) cout << 0 << endl; else ( while (n>0){ rem = n%2; count = rem? count + 1: 0; max = (count> max) ? count:max; d/=2; } } cout << max << endl; } int main(){ ........... ......... d_b(n); return 0; }
c#
int n = Convert.ToInt32(Console.ReadLine()); int count = 0; while (n > 0) { n = (n & (n >> 1)); count++; } Console.WriteLine(count);