Stern | C # program to print Brocot Sequence ; loop to create sequence ; adding sum of considered element and it 's precedent ; adding next considered element ; printing sequence . . ; Driver code ; adding first two element in the sequence
using System ; using System . Collections . Generic ; class GFG { static void SternSequenceFunc ( List < int > BrocotSequence , int n ) { for ( int i = 1 ; BrocotSequence . Count < n ; i ++ ) { int considered_element = BrocotSequence [ i ] ; int precedent = BrocotSequence [ i - 1 ] ; BrocotSequence . Add ( considered_element + precedent ) ; BrocotSequence . Add ( considered_element ) ; } for ( int i = 0 ; i < 15 ; ++ i ) Console . Write ( BrocotSequence [ i ] + " ▁ " ) ; } static void Main ( ) { int n = 15 ; List < int > BrocotSequence = new List < int > ( ) ; BrocotSequence . Add ( 1 ) ; BrocotSequence . Add ( 1 ) ; SternSequenceFunc ( BrocotSequence , n ) ; } }