Table of Contents
In this article, we will discuss the concept of the JavaScript program for dividing two numbers| in 4 different ways
In this post, we are going to learn how to write a program to find the division of two numbers and display the result on the screen in JS language
In this program, the user initiates the values to variables f_Num and l_Num, the program calculates the division of the given numbers using the division(/) operator in JavaScript.
Program 1
//JavaScript program to find division of two numbers const fNum=75; //declare and initaiize variable fNum const lNum=5; //declare and initaiize variable lNum //calculate division of two numbers const divNum=fNum/lNum; //display the division of two numbers console.log('The division of '+fNum+' and '+lNum+' is: '+divNum); //using concatenate operator
When the above code is executed, it produces the following result
The division of 75 and 5 is: 15
In this program, the user initiates the values to variables fNum and lNum, The program calculates the division of the given numbers using the division(/) operator inside the HTML tag
Program 2
<html> <head> <title>Dividing two numbers</title> <script> var fNum=35; var lNum=5; //Decare and initiaize variabes fNum and lNum var divRes=fNum/lNum; //Calculate division of two numbers //and assign the value to divRes variable document.write("Division of "+fNum+" and "+lNum+" is: "+divRes); //Print result on the screen using divRes variable </script> </head> <body> </body> </html>
When the above code is executed, it produces the following result
Division of 35 and 5 is: 7
In this program, the user is asked to enter values to variables f_Num and l_Num, the program calculates the division of the given numbers using the division(/) operator using the form.
Program 1
<html> <head> <title>Dividing two numbers</title> <script> //function to find division of two numbers function div() { var fNum,lNum,division; fNum=Number(document.getElementById("first").value); sNum=Number(document.getElementById("second").value); //Reading the values divRes=fNum/sNum; //Calculate division of two numbers document.getElementById("ans").innerHTML="Division:"+divRes; //display result on the screen } </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
Division of two numbers in JS – Entered by the user
In this program, the user is asked to enter values to variables f_Num and l_Num using the form, the program calculates the division of the given numbers using the division(/) operator, and then when we click the “clear” button, entered fields are cleared
Program 1
<html> <head> <title>Dividing two numbers</title> <script> //function to find division of two numbers function div() { var fNum,lNum,division; fNum=Number(document.getElementById("first").value); sNum=Number(document.getElementById("second").value); //Reading the values divRes=fNum/sNum; //Calculate division of two numbers document.getElementById("ans").innerHTML="Division:"+divRes; //display result on the screen } function clr()//function to clear all fields { document.getElementById("first").value=""; document.getElementById("second").value=""; document.getElementById("ans").innerHTML=""; } </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
Suggested post
Java program to divide two number
C program to divide two number
C++ program to divide two number
Python program to divide two number
java program to find the quotient and remainder
C program to find quotient and remainder
C++ program to find quotient and remainder
Python program to find quotient and remainder
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.