In this tutorial, we will discuss the title of the JavaScript: Calculate division of Two Numbers
In this topic, we are going to learn how to write a program to divide two numbers in the JavaScript programming language.
Program 1
Here, We use the division(/) operator to find the division of the given two numbers.
The program calculates the division of the two numbers 70 and 5; the output is displayed here.
// JavaScript program to division of two number const f_Num=70; //declare and initaiize variable f_Num const l_Num=5; //declare and initaiize variable l_Num //calculate division of given two numbers const div=f_Num/l_Num; //display the division of two numbers console.log('The division of '+f_Num+' and '+l_Num+' is: '+div);
When the above code is executed, it produces the following result
The division of 70 and 5 is: 14
Program 2
Here, We use the division(/) operator to find the division of two numbers. The program calculates the division of two numbers 30 and 5 then the output is displayed here using HTML
<html> <head> <title>Division of two numbers</title> <script> var fNumber=30; var lNumber=5; //Decare and initiaize variabes var div=fNumber/lNumber; //Calculate division of the given numbers //and assign the value to div variable document.write("Division of "+fNumber+" and "+lNumber+" is: "+div); //print result on the screen using div variable </script> </head> <body> </body> </html>
When the above code is executed, it produces the following result
Division of 30 and 5 is: 6
Program 3
The program asks the user to enter two numbers using the form, then the result of the division of two numbers is displayed when the user clicks the “division” button.
<html> <head> <title>Division of two numbers</title> <script> function div()//function to find division of given numbers { var fNum,lNum,division; fNum=Number(document.getElementById("first").value); sNum=Number(document.getElementById("second").value); division=fNum/sNum; document.getElementById("ans").innerHTML="Division:"+division; } </script> </head> <body> <p>Enter the first Number:<input type="text" id="first"></p> <p>Enter the second Number:<input type="text" id="second"></p> <button >When the above code is executed, it produces the following result
Similar post
Java program to divide two numbers
C program to divide two numbers
C++ program to divide two numbers
Python program to divide two numbers
Java program to divide two floating-point numbers
C program to divide two floating-point numbers
C++ program to divide two floating-point numbers
Python program to divide two floating-point numbers
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…