text: Trinomial Triangle | C # Program to print trinomial triangle . ; Function to find the trinomial triangle value . ; Using property of trinomial triangle . ; If value already calculated , return that . ; base case ; base case ; recursive step and storing the value . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driver Code
code: using System ; class GFG { private static int MAX = 10 ; public static int TrinomialValue ( int [ , ] dp , int n , int k ) { if ( k < 0 ) k = - k ; if ( dp [ n , k ] != 0 ) return dp [ n , k ] ; if ( n == 0 && k == 0 ) return 1 ; if ( k < - n k > n ) return 0 ; return ( dp [ n , k ] = TrinomialValue ( dp , n - 1 , k - 1 ) + TrinomialValue ( dp , n - 1 , k ) + TrinomialValue ( dp , n - 1 , k + 1 ) ) ; } public static void printTrinomial ( int n ) { int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = - i ; j <= 0 ; j ++ ) Console . Write ( TrinomialValue ( dp , i , j ) + " ▁ " ) ; for ( int j = 1 ; j <= i ; j ++ ) Console . Write ( TrinomialValue ( dp , i , j ) + " ▁ " ) ; Console . WriteLine ( ) ; } } static public void Main ( ) { int n = 4 ; printTrinomial ( n ) ; } }