how do you Write a program that accepts three decimal numbers as input and outputs their sum in javascript.
Answers
Answered by
0
Answer:
import java.util.*;
class nos
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter ay 3 decimal numbers");
double a[]=new Double[3];
double sum=0;
for(int i=0;i<3;i++)
{
a[i]=sc.nextDouble();
sum=sum+a[i];
}
System.out.println("The sum is "+ sum);
}
}
Answered by
0
Java Script Program:
Explanation:
var firtnumber=parseFloat(prompt("Enter the First decimal number"));//Take the first input.
var Secondnumber=parseFloat(prompt("Enter the Second decimal number"));//Take the second input.
var Thirdnumber=parseFloat(prompt("Enter the Third decimal number"));//Take the third input.
var result=firtnumber+Secondnumber+Thirdnumber;//Add the number
alert(result);//print the output.
Output:
- If the user gives the input as 1.5,1.5 and 1.5, then it will print the result as 4.5.
Code Explanation:
- The above code is in java script language, which take the three value from the alert box and print the sum of that value in the alert box.
- The Parsefloat function is used to convert the string value into float.
Learn More :
- Java Script : https://brainly.in/question/10407122
Similar questions