Question is at link -
Binary numbers
Code :
#include<iostream>
using namespace std;
int main(){
long long int n;
cin>>n;
int count=0;
while(n){
n = (n&(n<<1));
count++;
}
cout<<count;
return 0;
}
Sol :
We shift the binary digits of the number using shift operator and AND it.
No comments:
Post a Comment