diff --git a/Hacktoberfest2021/Count_ones_in_binary.cpp b/Hacktoberfest2021/Count_ones_in_binary.cpp new file mode 100644 index 0000000..a7e8128 --- /dev/null +++ b/Hacktoberfest2021/Count_ones_in_binary.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +int NumberOfOne(int n) +{ + int count=0; + while (n) + { + n=n & (n-1); + count++; + } + return count; +} + +int main() +{ + cout<