Write a JavaScript Program to Print Factorial of Any Number

JavaScript code:

<HTML>
  <HEAD>
    <TITLE>
    </TITLE>
  </HEAD>
  <BODY>
    <SCRIPT>
      var n,m,f=1;
      n=m=prompt("Enter a no :");
      if(n<0)
      {
        document.write("Factorial of negative no, can't be determined.");
      }
      else
      {
        While(n>0)
        {
          f=f*n;
          n--;
        }
        document.write("Factorial of "+m+"is= "+f);
      }
    </SCRIPT>
  </BODY>
</HTML>

Output:

Enter a no :
10
Factorial of 10 is= 3628800

Post a Comment

0 Comments