CALCULATOR USING SWITCH

 ************************************************************************ 

W.A.P TO MAKE A CALCULATOR USING SWITCH CASE

************************************************************************  

JAVA Program







   



  
Online compiler

Output:


************************************************************************ 

C Program



Online Compiler 

 

************************************************************************ 

C++ Program

Online Compiler

************************************************************************ 

C# Program


 
 
Output:

************************************************************************ 

PHP Program


Online Compiler

Php is a server side scripting language.

************************************************************************ 

JAVASCRIPT Program

<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title>
<script type="text/javascript">

function check() {
  var n1= document.getElementById('n1').value;  
  var n2= document.getElementById('n2').value;
  var op= document.getElementById('cal').value;
  var cc;
  switch(op)
  {
    case "+":
    cc= parseFloat(n1)+ parseFloat(n2);
    break;
    case "-":
    cc= parseFloat(n1) -parseFloat(n2);
    break;
    case "*":
    cc= parseFloat(n1)* parseFloat(n2);
    break;
    case "/":
    cc= parseFloat(n1) /parseFloat(n2);
    break;
    default:
    break;  
  }
  document.getElementById('ans').innerText= cc;
}
</script>
</head><body>
<input type="number" name="" id="n1"/>
<select id="cal">
  <option value="+" id="p">+</option>
  <option value="-" id="mi">-</option>
  <option value="*" id="mu">*</option>
  <option value="/" id="d">/</option>
</select>
<input type="number" name="" id="n2"/>
<br>
<button onclick="check()">CALCULATE</button>
<h2 id="ans" ></h2>

</body></html>

Online Compiler

************************************************************************ 

PYTHON Program

 

Online Compiler: 

************************************************************************  



















Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES