The trinomial triangle is a variation of Pascal’s triangle. The difference between the two is that an entry in the trinomial triangle is the sum of the three (rather than the two in Pasacal’s triangle) entries above it :

The k-th entry of the n-th row is denoted by :
![]()
Rows are counted starting from 0. The entries of the n-th row are indexed starting with -n from the left, and the middle entry has index 0. The symmetry of the entries of a row about the middle entry is expressed by the relationship
![]()
Properties :
- The n-th row corresponds to the coefficients in the polynomial expansion of the expansion of the trinomial (1 + x + x2) raised to the n-th power.

or Symmentrically

hence the alternative name trinomial coefficients because of their relationship to the multinomial coefficients :

- The diagonals have intersecting properties, such as their relationship to the triangular numbers.
- The sum of the elements of n-th row is 3n.
Recursion formula
The trinomial coefficients can be generated using the following recursion formula :
![]()
![]()
where,
, for k n
Applications :
- The triangle corresponds to the number of possible paths that can be taken by the king in a game of chess. The entry in a cell represents the number of different paths (using minimum number of moves) the king can take to reach the cell.
- The coefficient of xk in the polynomial (1 + x + x2)n specifies the number of different ways of randomly drawing k cards from two sets of n identical playing cards. For example, in such a card game with two sets of the three cards A, B, C , the choices look like this :
Given a positive number n. The task is to print Trinomial Triangle of height n.
Examples:
Input : n = 4 Output : 1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1 Input : n = 5 Output : 1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1 1 4 10 16 19 16 10 4 1
Below is the implementation of printing trinomial triangle og height n :
C++
// CPP Program to print trinomial triangle.#include<bits/stdc++.h>usingnamespacestd;// Function to find the trinomial triangle value.intTrinomialValue(intn,intk){// base caseif(n == 0 && k == 0)return1;// base caseif(k < -n || k > n)return0;// recursive step.returnTrinomialValue (n - 1, k - 1)+ TrinomialValue (n - 1, k)+ TrinomialValue (n - 1, k + 1);}// Function to print Trinomial Triangle of height n.voidprintTrinomial(intn){// printing n rows.for(inti = 0; i < n; i++){// printing first half of trianglefor(intj = -i; j <= 0; j++)cout << TrinomialValue(i, j) <<" ";// printing second half of triangle.for(intj = 1; j <= i; j++)cout << TrinomialValue(i, j) <<" ";cout << endl;}}// Driven Programintmain(){intn = 4;printTrinomial(n);return0;}chevron_rightfilter_noneJava
// Java Program to print trinomial triangle.importjava.util.*;importjava.lang.*;publicclassGfG {// Function to find the trinomial// triangle value.publicstaticintTrinomialValue(intn,intk){// base caseif(n ==0&& k ==0)return1;// base caseif(k < -n || k > n)return0;// recursive step.returnTrinomialValue(n -1, k -1)+ TrinomialValue(n -1, k)+ TrinomialValue(n -1, k +1);}// Function to print Trinomial// Triangle of height n.publicstaticvoidprintTrinomial(intn){// printing n rows.for(inti =0; i < n; i++){// printing first half of trianglefor(intj = -i; j <=0; j++)System.out.print(TrinomialValue(i, j)+" ");// printing second half of triangle.for(intj =1; j <= i; j++)System.out.print(TrinomialValue(i, j)+" ");System.out.println();}}// driver functionpublicstaticvoidmain(String argc[]){intn =4;printTrinomial(n);}}/* This code is contributed by Sagar Shukla */chevron_rightfilter_nonePython3
# Python3 code to print trinomial triangle.# Function to find the trinomial triangle value.defTrinomialValue(n, k):# base caseifn==0andk==0:return1# base casifk <-nork > n:return0# recursive step.return(TrinomialValue (n-1, k-1)+TrinomialValue (n-1, k)+TrinomialValue (n-1, k+1))# Function to print Trinomial Triangle of height n.defprintTrinomial( n ):# printing n rows.foriinrange(n):# printing first half of triangleforjinrange(-i,1):print(TrinomialValue(i, j),end=" ")# printing second half of triangle.forjinrange(1, i+1):print( TrinomialValue(i, j),end=" ")print("\n",end='')# Driven Coden=4printTrinomial(n)# This code is contributed by "Sharad_Bhardwaj".chevron_rightfilter_noneC#
// C# Program to print trinomial triangle.usingSystem;publicclassGfG {// Function to find the trinomial// triangle value.publicstaticintTrinomialValue(intn,intk){// base caseif(n == 0 && k == 0)return1;// base caseif(k < -n || k > n)return0;// recursive step.returnTrinomialValue(n - 1, k - 1)+ TrinomialValue(n - 1, k)+ TrinomialValue(n - 1, k + 1);}// Function to print Trinomial// Triangle of height n.publicstaticvoidprintTrinomial(intn){// printing n rows.for(inti = 0; i < n; i++){// printing first half of trianglefor(intj = -i; j <= 0; j++)Console.Write(TrinomialValue(i, j)+" ");// printing second half of triangle.for(intj = 1; j <= i; j++)Console.Write(TrinomialValue(i, j)+" ");Console.WriteLine();}}// Driver functionpublicstaticvoidMain(){intn = 4;printTrinomial(n);}}/* This code is contributed by Vt_m */chevron_rightfilter_nonePHP
<?php// PHP Program to print// trinomial triangle.// Function to find the// trinomial triangle value.functionTrinomialValue($n,$k){// base caseif($n== 0 &&$k== 0)return1;// base caseif($k< -$n||$k>$n)return0;// recursive step.returnTrinomialValue ($n- 1,$k- 1) +TrinomialValue ($n- 1,$k) +TrinomialValue ($n- 1,$k+ 1);}// Function to print Trinomial// Triangle of height n.functionprintTrinomial($n){// printing n rows.for($i= 0;$i<$n;$i++){// printing first// half of trianglefor($j= -$i;$j<= 0;$j++)echoTrinomialValue($i,$j)," ";// printing second// half of triangle.for($j= 1;$j<=$i;$j++)echoTrinomialValue($i,$j) ," ";echo"\n";}}// Driver Code$n= 4;printTrinomial($n);// This code is contributed// by ajit?>chevron_rightfilter_none
Output:1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1
Below is the implementation of printing Trinomial Triangle using Dynamic Programming and property of trinomial triangle i.e

C
// CPP Program to print trinomial triangle.#include<bits/stdc++.h>#define MAX 10usingnamespacestd;// Function to find the trinomial triangle value.intTrinomialValue(intdp[MAX][MAX],intn,intk){// Using property of trinomial triangle.if(k < 0)k = -k;// If value already calculated, return that.if(dp[n][k] != 0)returndp[n][k];// base caseif(n == 0 && k == 0)return1;// base caseif(k < -n || k > n)return0;// recursive step and storing the value.return(dp[n][k] = TrinomialValue(dp, n - 1, k - 1)+ TrinomialValue(dp, n - 1, k)+ TrinomialValue(dp, n - 1, k + 1));}// Function to print Trinomial Triangle of height n.voidprintTrinomial(intn){intdp[MAX][MAX] = { 0 };// printing n rows.for(inti = 0; i < n; i++){// printing first half of trianglefor(intj = -i; j <= 0; j++)cout << TrinomialValue(dp, i, j) <<" ";// printing second half of triangle.for(intj = 1; j <= i; j++)cout << TrinomialValue(dp, i, j) <<" ";cout << endl;}}// Driven Programintmain(){intn = 4;printTrinomial(n);return0;}chevron_rightfilter_noneJava
// Java Program to print trinomial triangle.importjava.util.*;importjava.lang.*;publicclassGfG {privatestaticfinalintMAX =10;// Function to find the trinomial triangle value.publicstaticintTrinomialValue(intdp[][],intn,intk){// Using property of trinomial triangle.if(k <0)k = -k;// If value already calculated, return that.if(dp[n][k] !=0)returndp[n][k];// base caseif(n ==0&& k ==0)return1;// base caseif(k < -n || k > n)return0;// recursive step and storing the value.return(dp[n][k] = TrinomialValue(dp, n -1, k -1)+ TrinomialValue(dp, n -1, k)+ TrinomialValue(dp, n -1, k +1));}// Function to print Trinomial Triangle of height n.publicstaticvoidprintTrinomial(intn){int[][] dp =newint[MAX][MAX];// printing n rows.for(inti =0; i < n; i++) {// printing first half of trianglefor(intj = -i; j <=0; j++)System.out.print(TrinomialValue(dp, i, j) +" ");// printing second half of triangle.for(intj =1; j <= i; j++)System.out.print(TrinomialValue(dp, i, j) +" ");System.out.println();}}// driver functionpublicstaticvoidmain(String argc[]){intn =4;printTrinomial(n);}}/* This code is contributed by Sagar Shukla */chevron_rightfilter_nonePython3
# Python3 code to print trinomial triangle.# Function to find the trinomial triangle value.defTrinomialValue(dp , n , k):# Using property of trinomial triangle.ifk <0:k=-k# If value already calculated, return that.ifdp[n][k] !=0:returndp[n][k]# base caseifn==0andk==0:return1# base caseifk <-nork > n:return0# recursive step and storing the value.return(TrinomialValue(dp, n-1, k-1)+TrinomialValue(dp, n-1, k)+TrinomialValue(dp, n-1, k+1))# Function to print Trinomial Triangle of height n.defprintTrinomial(n):dp=[[0]*10]*10# printing n rows.foriinrange(n):# printing first half of triangleforjinrange(-i,1):print(TrinomialValue(dp, i, j),end=" ")# printing second half of triangle.forjinrange(1,i+1):print(TrinomialValue(dp, i, j),end=" ")print("\n",end='')# Driven Programn=4printTrinomial(n)# This code is contributed by "Sharad_Bhardwaj".chevron_rightfilter_noneC#
// C# Program to print// trinomial triangle.usingSystem;classGFG{privatestaticintMAX = 10;// Function to find the// trinomial triangle value.publicstaticintTrinomialValue(int[,]dp,intn,intk){// Using property of// trinomial triangle.if(k < 0)k = -k;// If value already// calculated, return that.if(dp[n, k] != 0)returndp[n, k];// base caseif(n == 0 && k == 0)return1;// base caseif(k < -n || k > n)return0;// recursive step and storing the value.return(dp[n, k] = TrinomialValue(dp, n - 1,k - 1) +TrinomialValue(dp, n - 1,k) +TrinomialValue(dp, n - 1,k + 1));}// Function to print Trinomial// Triangle of height n.publicstaticvoidprintTrinomial(intn){int[,] dp =newint[MAX, MAX];// printing n rows.for(inti = 0; i < n; i++){// printing first// half of trianglefor(intj = -i; j <= 0; j++)Console.Write(TrinomialValue(dp, i,j) +" ");// printing second half// of triangle.for(intj = 1; j <= i; j++)Console.Write(TrinomialValue(dp, i,j) +" ");Console.WriteLine();}}// Driver CodestaticpublicvoidMain (){intn = 4;printTrinomial(n);}}// This code is contributed by ajitchevron_rightfilter_nonePHP
<?php// PHP Program to print// trinomial triangle.$MAX= 10;// Function to find the// trinomial triangle value.functionTrinomialValue($dp,$n,$k){// Using property of// trinomial triangle.if($k< 0)$k= -$k;// If value already// calculated, return that.if($dp[$n][$k] != 0)return$dp[$n][$k];// base caseif($n== 0 &&$k== 0)return1;// base caseif($k< -$n||$k>$n)return0;// recursive step and// storing the value.return($dp[$n][$k] = TrinomialValue($dp,$n- 1,$k- 1) +TrinomialValue($dp,$n- 1,$k) +TrinomialValue($dp,$n- 1,$k+ 1));}// Function to print Trinomial// Triangle of height n.functionprintTrinomial($n){global$MAX;$dp;for($i= 0;$i<$MAX;$i++)for($j= 0;$j<$MAX;$j++)$dp[$i][$j] = 0;// printing n rows.for($i= 0;$i<$n;$i++){// printing first// half of trianglefor($j= -$i;$j<= 0;$j++)echoTrinomialValue($dp,$i,$j)." ";// printing second// half of triangle.for($j= 1;$j<=$i;$j++)echoTrinomialValue($dp,$i,$j)." ";echo"\n";}}// Driven Code$n= 4;printTrinomial($n);// This code is contributed by mits?>chevron_rightfilter_none
Output:1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

