Skip to content

Commit

Permalink
Added Arithmetic Geometric Calculator #987
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshika14528 committed Jun 4, 2024
1 parent 3c1358d commit 693cc61
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 223 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# <p align="center">Arithmetic Progression Calculator</p>
# Arithmetic-Geometric Progression Calculator

## Description :-

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

## Tech Stacks :-

Expand All @@ -12,4 +12,4 @@ Calculates nth Term and sum of n Terms present in an Arithematic Sequence.

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/49ea9259-ad15-45b2-9e30-1a05184ae28b)
![image]()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 14 additions & 9 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@
<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>
<title>Arithmetic Geometric Progressionn Calculator</title>
</head>

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

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

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

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

<label for="calculationType">Choose Calculation:</label>

<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>
Expand Down
40 changes: 33 additions & 7 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,57 @@
function calculate() {
// Get input values
const firstTerm = parseFloat(document.getElementById('firstTerm').value);
const commonDifference = parseFloat(document.getElementById('commonDifference').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, commonDifference, termNumber);
result = calculateNthTerm(firstTerm, commonRatio, termNumber, commonDifference);
} else if (calculationType === 'sumOfTerms') {
// Calculate the sum of the first n terms
result = calculateSumOfTerms(firstTerm, commonDifference, termNumber);
result = calculateSumOfTerms(firstTerm, commonRatio, termNumber, commonDifference);
}

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

function calculateNthTerm(firstTerm, commonDifference, termNumber) {
function calculateNthTerm(firstTerm, commonRatio, termNumber, commonDifference) {
// Calculate the nth term
return `The ${termNumber}th term is: ${firstTerm + (termNumber - 1) * commonDifference}`;
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, commonDifference, termNumber) {
function calculateSumOfTerms(firstTerm, commonRatio, termNumber, commonDifference) {
// Calculate the sum of the first n terms
return `The sum of the first ${termNumber} terms is: ${(termNumber / 2) * (2 * firstTerm + (termNumber - 1) * commonDifference)}`;
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}`;
}
33 changes: 20 additions & 13 deletions Calculators/Arithmetic-Geometric-Progression-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
background-color: #85e3e0;
background-image: url('assets/background.jpeg');
background-size: cover;
background-position: center;
}

header {
background-color: #6bc1e9;
color: #fff;
text-align: center;
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 #ccc;
border: 1px solid #cccccc;
padding: 20px;
border-radius: 8px;
background: linear-gradient(to right, #64cee6, #9198e5);
background-color: #fff;
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: #333;
color: #333333;
}

input,
Expand All @@ -35,16 +42,16 @@ select {
padding: 10px;
margin-bottom: 16px;
box-sizing: border-box;
border-radius: 9px;
border-radius: 10px;
}

button {
width: 100%;
height: 40px;
font-size: 16px;
cursor: pointer;
background-color: #28f2fc;
color: #fff;
background-color: #2856fc;
color: #ffffff;
border: none;
border-radius: 9px;
transition: background-color 0.3s;
Expand All @@ -57,5 +64,5 @@ button:hover {
#result {
margin-top: 16px;
font-weight: bold;
color: #333;
color: #333333;
}
Loading

0 comments on commit 693cc61

Please sign in to comment.