Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mean functionality in Arithmetic Progression Calculator #1791

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Calculators/Arithmetic-Progression-Calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description :-

Calculates nth Term and sum of n Terms present in an Arithematic Sequence.
Calculates nth Term, arithmetic mean and sum of n Terms present in an Arithematic Sequence.

## Tech Stacks :-

Expand Down
1 change: 1 addition & 0 deletions Calculators/Arithmetic-Progression-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1>Arithmetic Progression Calculator</h1>
<select id="calculationType">
<option value="nthTerm">Nth Term</option>
<option value="sumOfTerms">Sum of First N Terms</option>
<option value="arithMean">Arithmetic Mean</option>
</select>

<button onclick="calculate()">Calculate</button>
Expand Down
8 changes: 8 additions & 0 deletions Calculators/Arithmetic-Progression-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function calculate() {
} else if (calculationType === 'sumOfTerms') {
// Calculate the sum of the first n terms
result = calculateSumOfTerms(firstTerm, commonDifference, termNumber);
} else if (calculationType === 'arithMean') {
// Calculate the arithmetic mean of terms
result = calculateArithMean(firstTerm, commonDifference, termNumber);
}

// Display the result
Expand All @@ -29,3 +32,8 @@ function calculateSumOfTerms(firstTerm, commonDifference, termNumber) {
// Calculate the sum of the first n terms
return `The sum of the first ${termNumber} terms is: ${(termNumber / 2) * (2 * firstTerm + (termNumber - 1) * commonDifference)}`;
}

function calculateArithMean(firstTerm, commonDifference, termNumber) {
// Calculate the arithmetic mean of terms
return `The arithmetic mean of ${termNumber} terms is: ${(1 / 2) * (2 * firstTerm + (termNumber - 1) * commonDifference)}`;
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ <h3>Calculates nth Term and sum of n Terms of the Arithmetic Geometric Sequence.
<div class="box">
<div class="content">
<h2>Arithmetic Progression Calculator</h2>
<h3>Calculates nth Term and sum of n Terms present in an Arithmetic Sequence.</h3>
<h3>Calculates nth Term, arithmetic mean and sum of n Terms present in an Arithmetic Sequence.</h3>
<div class="card-footer">
<a href="./Calculators/Arithmetic-Progression-Calculator/index.html" target="_blank">
<button>Try Now</button>
Expand Down