Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

HCF Program in JS with flowchart and form values entered by the user

HCF Program in JS with flowchart and form values entered by the user
In this tutorial, we will try to learn the followings;

  1. Flowchart of the HCF program 
  2. Javascript program to show the HCF.
  3. javascript program to show the HCF with the form values entered by the user.

Flowchart of the HCF program 

HCF Program in JS with flowchart and form values entered by user

HCF Program in JS with flowchart and form values entered by the user

Javascript program to show the HCF.

<!DOCTYPE html>
<html>
<body>

<h1>Java Script</h1>
<h2>H C F in JAVASCRIPT<h2>
<p>Given the first value is 4</p>
<p>Given the second value is 6</p>


<script>
function gcd() {
var m,n;
m=4;
n=6;
while(m!=n){
if(m>n)
{m=m-n;
document.write("\nH.C.F of 4 & 6 is "+m);
}
else
{
n=n-m;
}
}
}

</script>

    <input type="button" value="show Result" OnClick="gcd()"/>


</body>
</html>

javascript program to show the HCF with the form values entered by the user.

<!DOCTYPE html>
<html>
<body>

<h1>Java Script</h1>
<h2>H C F in JAVASCRIPT<h2>


<script>
function gcd(a,b) {
var m,n;
m=a;
n=b;

while(m!=n){
if(m>n)
m=m-n;
else
n=n-m;
}



document.write("\nH.C.F of "+a+" & "+b+" is "+m);

}

</script>

Enter a value:<input type="text" name="enter" class="enter" value="" id="first"/></br></br>
Enter a value:<input type="text" name="enter" class="enter" value="" id="second"/></br>
    <input type="button" value="show Result" OnClick="gcd(document.getElementById('first').value,document.getElementById('second').value)"/>


</body>
</html>

Topic Covered

HCF Program in JS with flowchart and form values entered by the user
  List of All Programs of Javascript : Click Here 
.

Prof. Fzal Rehman Shamil
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325