From 43ecece1c149a39be476f7a0f0d65d500e18361a Mon Sep 17 00:00:00 2001 From: Shaurya Raghuvanshi <112566627+shaurya-clemson@users.noreply.github.com> Date: Thu, 30 Nov 2023 01:34:28 -0500 Subject: [PATCH] Create find_sum_of_gp_series.dart Find sum of gp series program in Dart --- .../find_sum_of_gp_series.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 program/program/find-sum-of-gp-series/find_sum_of_gp_series.dart diff --git a/program/program/find-sum-of-gp-series/find_sum_of_gp_series.dart b/program/program/find-sum-of-gp-series/find_sum_of_gp_series.dart new file mode 100644 index 000000000..6e60132f0 --- /dev/null +++ b/program/program/find-sum-of-gp-series/find_sum_of_gp_series.dart @@ -0,0 +1,19 @@ +import 'dart:math'; + +void main() { + + int a1 = 2; // First term of the GP + int r = 3; // Common ratio + int n = 3; // Number of terms + + // Calculating the sum of the GP series + double sum = calculateGPSum(a1, r, n); + + // Printing the output + print("Sum of GP series: $sum"); +} + +double calculateGPSum(int a1, int r, int n) { + // Using the formula for the sum of GP series + return a1 * (pow(r, n) - 1) / (r - 1); +}