Gould 's Sequence | CPP program to generate Gould 's Sequence ; Utility function to count odd numbers in ith row of Pascals 's triangle ; Initialize count as zero ; Return 2 ^ count ; Function to generate gould 's Sequence ; loop to generate gould 's Sequence up to n ; Driver code ; Get n ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countOddNumber ( int row_num ) { unsigned int count = 0 ; while ( row_num ) { count += row_num & 1 ; row_num >>= 1 ; } return ( 1 << count ) ; } void gouldSequence ( int n ) { for ( int row_num = 0 ; row_num < n ; row_num ++ ) { cout << countOddNumber ( row_num ) << " ▁ " ; } } int main ( ) { int n = 16 ; gouldSequence ( n ) ; return 0 ; }