Skip to content

Commit

Permalink
Added Arithmetic Geometric Progression Calculator (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshika14528 authored Jun 5, 2024
1 parent 2d66f32 commit e9ce38d
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Arithmetic Geometric Progression Calculator</p>

## Description :-

Calculates the nth Term and sum of n Terms of the Arithematic-Geometric Sequence.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/b9e14255-30e4-48f5-8134-8b472bfd12a3)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Arithmetic Geometric Progression Calculator</title>
</head>

<body>
<header>
<h1>Arithmetic Geometric Progression Calculator</h1>
</header>

<section id="calculator">
<label for="firstTerm">First Term (a):</label>
<input type="number" id="firstTerm" required placeholder="Enter (a)">

<label for="commonRatio">Common Ratio (r):</label>
<input type="number" id="commonRatio" required placeholder="Enter (r)">

<label for=" commonDifference">Common Difference (d):</label>
<input type="number" id="commonDifference" required placeholder="Enter (d)">

<label for=" termNumber">Term Number (n):</label>
<input type="number" id="termNumber" required placeholder="Enter (n)">

<label for=" calculationType">Choose Calculation:</label>
<select id="calculationType">
<option value="nthTerm">Nth Term</option>
<option value="sumOfTerms">Sum of First N Terms</option>
</select>

<button onclick="calculate()">Calculate</button>

<p id="result"></p>
</section>

<script src="script.js"></script>
</body>

</html>
55 changes: 55 additions & 0 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function calculate() {
// Get input values
const firstTerm = parseFloat(document.getElementById('firstTerm').value);
const commonRatio = parseFloat(document.getElementById('commonRatio').value);
const termNumber = parseInt(document.getElementById('termNumber').value);
const commonDifference = parseInt(document.getElementById('commonDifference').value);
const calculationType = document.getElementById('calculationType').value;

const n = termNumber;
const a = firstTerm;
const d = commonDifference;
const r = commonRatio;
if (isNaN(a) || isNaN(d) || isNaN(n) || isNaN(r)) {
document.getElementById("result").innerText = "Please enter the valid numbers for all fields.";
return;
}
// Perform the selected calculation
let result;
if (calculationType === 'nthTerm') {
// Calculate the nth term
result = calculateNthTerm(firstTerm, commonRatio, termNumber, commonDifference);
} else if (calculationType === 'sumOfTerms') {
// Calculate the sum of the first n terms
result = calculateSumOfTerms(firstTerm, commonRatio, termNumber, commonDifference);
}

// Display the result
const resultElement = document.getElementById('result');
resultElement.textContent = result;
}

function calculateNthTerm(firstTerm, commonRatio, termNumber, commonDifference) {
// Calculate the nth term
const n = termNumber;
const a = firstTerm;
const d = commonDifference;
const r = commonRatio;
const m = (Math.pow(commonRatio, termNumber - 1));

return `The ${termNumber}th term is: ${(a + (n - 1) * d) * m}`;
}

function calculateSumOfTerms(firstTerm, commonRatio, termNumber, commonDifference) {
// Calculate the sum of the first n terms
const n = termNumber;
const a = firstTerm;
const d = commonDifference;
const r = commonRatio;
const p = 1 - commonRatio;
const l = (1 - Math.pow(commonRatio, termNumber - 1));
const m = (Math.pow(commonRatio, termNumber));
const w = Math.pow(p, 2);

return `The sum of the first ${termNumber} terms is: ${(a / p) + ((d * r * l) / w) - (((a + (n - 1) * d) * m)) / p}`;
}
67 changes: 67 additions & 0 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #85e3e0;
background-image: url('assets/background.jpeg');
background-size: cover;
background-position: center;
}

header {
padding: 1em;
font-weight: bold;
font-size: larger;
color: #f7f6f6;
text-align: center;
text-decoration: underline;
}

#calculator {
max-width: 300px;
margin: 20px auto;
border: 1px solid #cccccc;
padding: 20px;
border-radius: 8px;
background: linear-gradient(to right, #6498e6, #91a7e5);
background-color: #627a8d;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

label {
font-weight: bold;
display: block;
margin-bottom: 8px;
color: #333333;
}

input,
select {
width: 100%;
padding: 10px;
margin-bottom: 16px;
box-sizing: border-box;
border-radius: 10px;
}

button {
width: 100%;
height: 40px;
font-size: 16px;
cursor: pointer;
background-color: #2856fc;
color: #ffffff;
border: none;
border-radius: 9px;
transition: background-color 0.3s;
}

button:hover {
background-color: #45a09e;
}

#result {
margin-top: 16px;
font-weight: bold;
color: #333333;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ <h3>Calculates the antilog of the any given number taken over any base.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Arithmetic Geometric Progression Calculator</h2>
<h3>Calculates nth Term and sum of n Terms of the Arithmetic Geometric Sequence.</h3>
<div class="card-footer">
<a href="./Calculators/Arithmetic-Geometric-Progression-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Arithmetic-Geometric-Progression-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Arithmetic Progression Calculator</h2>
Expand Down

0 comments on commit e9ce38d

Please sign in to comment.