Skip to content

Commit

Permalink
Added Euclidean-Algorithm-Calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalesh-og committed Jun 6, 2024
1 parent 551f76e commit 68dd3f4
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Calculators/Euclidean-Algorithm-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Euclidean Algorithm Calculator

### Functionality :-
This calculator is a simple tool that to compute the Greatest Common Divisor (GCD) and the Least Common Multiple (LCM) of two integers entered by the user.


### Built Using :-

- HTML
- CSS
- JavaScript


### Screenshot :-
Sample Output 1 :-
![image](https://github.com/Rakesh9100/CalcDiverse/assets/163159351/ce50851a-29df-48b8-8021-dd818fb4b39c)

Sample Output 2 :-
![image](https://github.com/Rakesh9100/CalcDiverse/assets/163159351/baeef276-de95-4e75-b867-dec63d6b0ea5)
40 changes: 40 additions & 0 deletions Calculators/Euclidean-Algorithm-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Euclidean Algorithm Calculator</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<h1>Euclidean Algorithm</h1>
<p>
The Euclidean algorithm efficiently computes the greatest common divisor (GCD) of two integers,
which is the largest number that divides both without a remainder. Additionally, you can find the
least common multiple (LCM) using the GCD with the formula: LCM(A, B) = (A * B) / GCD(A, B).
</p>
<form class="form-container">
<div class="inp-container">
<div class="values">
<label for="val1">VALUE 1</label>
<input type="number" class="num1" placeholder="Enter first number" min="1" />
</div>
<div class="values">
<label for="val2">VALUE 2</label>
<input type="number" class="num2" placeholder="Enter second number" min="1" />
</div>
</div>
<button type="submit" class="submit">CALCULATE</button>
</form>
<h2 class="gcd-final">
GCD(<span class="n1"></span>, <span class="n2"></span>) = <span class="gcd"></span>
</h2>
<h2 class="lcm-final">
LCM(<span class="n3"></span>, <span class="n4"></span>) = <span class="lcm"></span>
</h2>
</div>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions Calculators/Euclidean-Algorithm-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const form=document.querySelector(".form-container")
const submitBtn=document.querySelector(".submit")
form.addEventListener("submit",calculate);

function calculate(e){
e.preventDefault();
let a=document.querySelector(".num1").value;
let b=document.querySelector(".num2").value;

let res=gcd(a,b);
let res2=lcm(a,b);

const gcdFinal=document.querySelector(".gcd-final");
const lcmFinal=document.querySelector(".lcm-final");

const gcdVal=document.querySelector(".gcd");
const lcmVal=document.querySelector(".lcm");
const num1=document.querySelector(".n1");
const num2=document.querySelector(".n2");
const num3=document.querySelector(".n3");
const num4=document.querySelector(".n4");

gcdVal.innerText=res;
lcmVal.innerText=res2;

num1.innerText=a;
num2.innerText=b;
num3.innerText=a;
num4.innerText=b;

gcdFinal.classList.add("show");
lcmFinal.classList.add("show");
}
function gcd(a,b){
var r;
while((a%b)>0){
r=a%b
a=b
b=r
}
return b
}
function lcm(a,b){
return a*b/gcd(a,b);
}
125 changes: 125 additions & 0 deletions Calculators/Euclidean-Algorithm-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap');

* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Open Sans', sans-serif;
user-select: none;
}

body {
background: linear-gradient(135deg, #2a2a2a, #121212);
color: #e0e0e0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}

.container {
background: rgba(30, 30, 30, 0.9);
border-radius: 15px;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
text-align: center;
max-width: 600px;
padding: 40px 20px;
backdrop-filter: blur(10px);
}

.container h1 {
font-size: 32px;
color: #ffffff;
font-weight: 700;
text-transform: uppercase;
margin-bottom: 20px;
letter-spacing: 2px;
}

.container p {
font-size: 16px;
color: #b0b0b0;
margin-bottom: 30px;
line-height: 1.6;
animation: fadeIn 2s ease-in-out;
}

.inp-container {
display: flex;
flex-direction: column;
gap: 20px;
}

.values {
display: flex;
flex-direction: column;
align-items: flex-start;
}

.inp-container label {
font-size: 14px;
color: #cccccc;
margin-bottom: 5px;
}

.inp-container input {
width: 100%;
padding: 10px;
border: 1px solid #444;
border-radius: 8px;
background: #2c2c2c;
color: #e0e0e0;
font-size: 16px;
transition: all 0.3s ease;
}

.inp-container input:focus {
border-color: #3498db;
box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.submit {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
font-weight: 500;
color: #ffffff;
background: linear-gradient(135deg, #3498db, #2ecc71);
border: none;
border-radius: 8px;
cursor: pointer;
transition: background 0.3s ease;
}

.submit:hover {
background: linear-gradient(135deg, #2980b9, #27ae60);
}

.gcd-final, .lcm-final {
margin-top: 20px;
font-size: 20px;
color: #ffffff;
display: none;
animation: fadeIn 1s ease-in-out;
}

.gcd-final.show, .lcm-final.show {
display: block;
}

.gcd-final .gcd, .lcm-final .lcm {
color: #e74c3c;
font-weight: 700;
}

@keyframes fadeIn {
0% {
opacity: 0;
transform: translateY(-20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,20 @@ <h3>Calculates the Equivalent Resistance of the Series and Parallel Configuratio
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Euclidean-Algorithm-Calculator</h2>
<h3>Calculates the Greatest Common Divisor (GCD) and the Least Common Multiple (LCM).</h3>
<div class="card-footer">
<a href="./Calculators\Euclidean-Algorithm-Calculator\index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Euclidean-Algorithm-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>Expenditure And Savings Calculator</h2>
Expand Down

0 comments on commit 68dd3f4

Please sign in to comment.