Calculate the number of set bits for every number from 0 to N | C ++ implementation of the approach ; Function to find the count of set bits in all the integers from 0 to n ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findSetBits ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) cout << __builtin_popcount ( i ) << " ▁ " ; } int main ( ) { int n = 5 ; findSetBits ( n ) ; return 0 ; }