Print first N terms of Lower Wythoff sequence | C ++ implementation of the approach ; Function to print the first n terms of the lower Wythoff sequence ; Calculate value of phi ; Find the numbers ; a ( n ) = floor ( n * phi ) ; Print the nth numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void lowerWythoff ( int n ) { double phi = ( 1 + sqrt ( 5 ) ) / 2.0 ; for ( int i = 1 ; i <= n ; i ++ ) { double ans = floor ( i * phi ) ; cout << ans ; if ( i != n ) cout << " , ▁ " ; } } int main ( ) { int n = 5 ; lowerWythoff ( n ) ; return 0 ; }