Golomb sequence | C ++ Program to find first n terms of Golomb sequence . ; Return the nth element of Golomb sequence ; base case ; Recursive Step ; Print the first n term of Golomb Sequence ; Finding first n terms of Golomb Sequence . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findGolomb ( int n ) { if ( n == 1 ) return 1 ; return 1 + findGolomb ( n - findGolomb ( findGolomb ( n - 1 ) ) ) ; } void printGolomb ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) cout << findGolomb ( i ) << " ▁ " ; } int main ( ) { int n = 9 ; printGolomb ( n ) ; return 0 ; }