Program to find nth term of the series 1 4 15 24 45 60 92 | C ++ implementation of the above approach ; function to calculate nth term of the series ; variable nth will store the nth term of series ; if n is even ; if n is odd ; return nth term ; Driver code
#include <stdio.h> NEW_LINE long long int nthTerm ( long long int n ) { long long int nth ; if ( n % 2 == 0 ) nth = 2 * ( ( n * n ) - n ) ; else nth = ( 2 * n * n ) - n ; return nth ; } int main ( ) { long long int n ; n = 5 ; printf ( " % lld STRNEWLINE " , nthTerm ( n ) ) ; n = 25 ; printf ( " % lld STRNEWLINE " , nthTerm ( n ) ) ; n = 25000000 ; printf ( " % lld STRNEWLINE " , nthTerm ( n ) ) ; n = 250000007 ; printf ( " % lld STRNEWLINE " , nthTerm ( n ) ) ; return 0 ; }