-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Arithmetic Geometric Progression Calculator (#1177)
- Loading branch information
1 parent
2d66f32
commit e9ce38d
Showing
6 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Calculators/Arithmetic-Geometric-Progression-Calculator/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Binary file added
BIN
+292 KB
Calculators/Arithmetic-Geometric-Progression-Calculator/assets/background.jpeg
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
43
Calculators/Arithmetic-Geometric-Progression-Calculator/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
Calculators/Arithmetic-Geometric-Progression-Calculator/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
Calculators/Arithmetic-Geometric-Progression-Calculator/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters