From 56244b7ee237bfaf1cba814cd82c2afa0329f28c Mon Sep 17 00:00:00 2001 From: Ayush Kumar Date: Fri, 24 Jul 2020 12:58:18 +1300 Subject: [PATCH] Count_setbits source file added --- cpp/Count_setbits.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 cpp/Count_setbits.cpp 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<