FACTORIAL OF A NUMBER

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

W.A.P TO FIND FACTORIAL OF A NUMBER

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

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">

var fact=1;
function factr(n){
  if(n <= 1){
    return 1;
  }
  else{
    return (n * factr(n-1));
  }
}

function check() {
  var a = document.getElementById('n1').value;
  // if (a==0)
  // {
  //  document.getElementById('ans').innerText= `The factorial value of ${a} is 1`;
  // }
  // else
  if(a < 0){
 document.getElementById('ans').innerText= `The factorial value of ${a} is not possible`;
  }
  else{
   var fact = factr(a);
    document.getElementById('ans').innerText= `The factorial value of ${a} is ${fact}`;
  }
}
</script>
</head><body>
<input type="number" name="" id="n1"/>
<br>
<button onclick="check()">CALCULATE</button>
<h2 id="ans" ></h2>

</body></html>

Online Compiler

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

PYTHON Program

 

Online Compiler: 

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


















Comments

Popular posts from this blog

PALINDROME NUMBER

CONVERT CARTESIAN COORDINATES TO POLAR COORDINATE

FIBONACCI SERIES