Nth term of a recurrence relation generated by two given arrays | C # program for the above approach ; Function to calculate Nth term of general recurrence relations ; Stores the generated sequence ; Current term is sum of previous k terms ; Print the nth term ; Driver Code ; Given Array F [ ] and C [ ] ; Given N and K ; Function call
using System ; class GFG { static double mod = 1e9 + 7 ; static void NthTerm ( int [ ] F , int [ ] C , int K , int n ) { int [ ] ans = new int [ n + 1 ] ; for ( int i = 0 ; i < K ; i ++ ) ans [ i ] = F [ i ] ; for ( int i = K ; i <= n ; i ++ ) { for ( int j = i - K ; j < i ; j ++ ) { ans [ i ] += ans [ j ] ; ans [ i ] %= ( int ) mod ; } } Console . WriteLine ( ans [ n ] ) ; } public static void Main ( String [ ] args ) { int [ ] F = { 0 , 1 } ; int [ ] C = { 1 , 1 } ; int K = 2 ; int N = 10 ; NthTerm ( F , C , K , N ) ; } }