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.
Your code is slightly wrong. For example - 23 , it's binary representation is 10111. So the maximum no. of consecutive 1's should be 3 but if you try running the code above it will give the result as 1 because it just stores the latest no. of 1's.
So what you can do is :
else{
t=s;
s=0;
}
if(t
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
Your code is slightly wrong. For example - 23 , it's binary representation is 10111. So the maximum no. of consecutive 1's should be 3 but if you try running the code above it will give the result as 1 because it just stores the latest no. of 1's. So what you can do is : else{ t=s; s=0; } if(t