Find nth term of a given recurrence relation | C ++ program to find nth term of a given recurrence relation ; function to return required value ; Get the answer ; Return the answer ; Driver program ; Get the value of n ; function call to print result
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sum ( int n ) { int ans = ( n * ( n - 1 ) ) / 2 ; return ans ; } int main ( ) { int n = 5 ; cout << sum ( n ) ; return 0 ; }