• Courses
• Data Structure
• ### HTML and JavaScript Code to find the GCD (Greatest Common Division) of two numbers.

Posted on 2021-08-02

According to Wikipedia - In mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4.

Here in this page I have shared HTML and Javascript program to find the greatest common division of two number.

Example:

```<!DOCTYPE html>
<html>
<title> GCD Using Euclidean Algorithm </title>
<style>
.main{
background-color: lime;
margin: auto;
width: 40%;
border: 3px solid green;
margin-top: 100px;
}

background-color: rgb(230, 146, 230);
text-align: center;
margin-bottom: 15px;
}

.result{
font-size: 40px;
margin-left: 50px;
}

.btn{
background-color: #2d0af5; /* Green */
border: none;
color: white;
text-align: center;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}

input[type=number] {
width: 100%;
box-sizing: border-box;
border: 2px solid #ccc;
font-size: 16px;
background-color: white;
}
</style>
<body>

<div class="main">
<h2> GCD (Find Greatest Common Division) </h2>
</div>

<div style="text-align: center">
<input type="number" placeholder="Enter R1" id="r1" required> <br> <br>
<input type="number" placeholder="Enter R2" id="r2" required> <br> <br>

<button class="btn" type="button" onclick="getInputValue();">Get Value</button>
</div>
<hr>
<div class="result">
GCD = <span id="gcd" style="color: #ff0000"></span>
</div>
</div>

<div style="background-color: #ccc; padding: 2px; bottom: 0; position: fixed; width: 100%;">
<marquee>
<p> Created By Raj </p>
</marquee>
</div>

<script>

function gcd(a, b) {
var R;
while ((a % b) > 0)  {
R = a % b;
a = b;
b = R;
}
return b;
}

function getInputValue(){
var r1 = document.getElementById("r1").value;
var r2 = document.getElementById("r2").value;
console.log(r1);
console.log(r2);
document.getElementById("gcd").innerHTML = gcd(r1, r2);
}

</script>
</html>
```

922

#### Recent Guides

 Secondary Level Teaching License Examination Sample question paper Secondary Level General Examination Sample question paper-2078 English, Lower Secondary Level Sample question paper-2078 English, Secondary Level Sample Question Paper-2078