Sum of Arithmetic Geometric Sequence | C # Program to find the sum of first n terms . ; Return the sum of first n term of AGP ; Finding the each term of AGP and adding it to sum . ; Driver Code
using System ; class GFG { static int sumofNterm ( int a , int d , int b , int r , int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += ( int ) ( ( a + ( i - 1 ) * d ) * ( b * Math . Pow ( r , i - 1 ) ) ) ; return sum ; } public static void Main ( ) { int a = 1 , d = 1 , b = 2 , r = 2 , n = 3 ; Console . Write ( sumofNterm ( a , d , b , r , n ) ) ; } }