Motzkin number | CPP Program to find Nth Motzkin Number . ; Return the nth Motzkin Number . ; Base Case ; Recursive step ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int motzkin ( int n ) { if ( n == 0 n == 1 ) return 1 ; return ( ( 2 * n + 1 ) * motzkin ( n - 1 ) + ( 3 * n - 3 ) * motzkin ( n - 2 ) ) / ( n + 2 ) ; } int main ( ) { int n = 8 ; cout << motzkin ( n ) << endl ; return 0 ; }