Geek | Function to calculate the N - th Geek - onacci Number ; Stores the geekonacci series ; Store the first three terms of the series ; Iterate over the range [ 3 , N ] ; Update the value of arr [ i ] as the sum of previous 3 terms in the series ; Return the last element of arr [ ] as the N - th term ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int find ( int A , int B , int C , int N ) { int arr [ N ] ; arr [ 0 ] = A ; arr [ 1 ] = B ; arr [ 2 ] = C ; for ( int i = 3 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + arr [ i - 2 ] + arr [ i - 3 ] ; } return arr [ N - 1 ] ; } int main ( ) { int A = 1 , B = 3 , C = 2 , N = 4 ; cout << ( find ( A , B , C , N ) ) ; return 0 ; }