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
using System ; class GFG { static int count ( int n ) { int count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } static void findSetBits ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) Console . Write ( count ( i ) + " ▁ " ) ; } public static void Main ( String [ ] args ) { int n = 5 ; findSetBits ( n ) ; } }