Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Create find_sum_of_gp_series.dart #4804

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions program/program/find-sum-of-gp-series/find_sum_of_gp_series.dart
Original file line number Diff line number Diff line change
@@ -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);
}