Padovan Sequence | C ++ program to find n 'th term in Padovan Sequence using Dynamic Programming ; Function to calculate padovan number P ( n ) ; 0 th , 1 st and 2 nd number of the series are 1 ; Driver Program
#include <iostream> NEW_LINE using namespace std ; int pad ( int n ) { int pPrevPrev = 1 , pPrev = 1 , pCurr = 1 , pNext = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { pNext = pPrevPrev + pPrev ; pPrevPrev = pPrev ; pPrev = pCurr ; pCurr = pNext ; } return pNext ; } int main ( ) { int n = 12 ; cout << pad ( n ) ; return 0 ; }