diff --git a/cpp/Count_setbits.cpp b/cpp/Count_setbits.cpp new file mode 100644 index 000000000..7ddc21cce --- /dev/null +++ b/cpp/Count_setbits.cpp @@ -0,0 +1,28 @@ +//program to count the set bits +#include +using namespace std; + +int main() +{ + int t; + cout<<"Enter the number of test cases"<<" "; + cin>>t; + while(t--) + { + int n; + cout<<"Enter the number do you want"<>n; + int count=0; + while(n!=0) + { + if(n&1==1) + { + count++; + } + n=n>>1; + } + cout<<"The number of set bits:"<<" "; + cout<