JavaScript Program To Perform Arithmetic Operation

As you know that arithmetic Operation means addition, subtraction, multiplication, division and Reminder. If you perform one arithmetic operation or all, Then you required operator as like ( +, -, *, / ) and required two operands. In C, C++, java and JavaScript, all languages are performing arithmetic operation. In all languages syntax are different but logic are same.
JavaScript-arithmetic-operation-operator-decoderp

Algorithm

Step:1 Start
Step:2 Read two numbers a and b.
Step:3 a+b, a-b, a*b, a/b, a%b .
Step:4 Print Results.
Step:5 Stop.

JavaScript code

<HTML>
  <HEAD>
    <TITLE>
    </TITLE>
  </HEAD>
  <BODY>
    <SCRIPT>
     var a=prompt("Enter a no:");
     var b=prompt("Enter another no:");
     document.write(a+" + "+b+" = "+(Number(a)+Number(b)));
     document.write("<br/>"+a+" - "+b+" = "+(Number(a)-Number(b)));
     document.write("<br/>"+a+" / "+b+" = "+Number(a)/Number(b));
     document.write("<br/>"+a+" * "+b+" = "+Number(a)*Number(b));
     document.write("<br/>"+a+" % "+b+" = "+Number(a)%Number(b));
     </SCRIPT>
  </BODY>
</HTML>

Output :

Enter a no:
12
Enter another no:
6
12 + 6 = 18
12 - 6 = 6
12 / 6 = 2
12 * 6 = 72
12 % 6 = 0

Post a Comment

0 Comments