For Advertisements on this blog Contact Us at developgram@gmail.com or +91-9923438816

Simple Programming Tutorials For Beginners

Tuesday, April 18, 2017

Prime Number

<html>
<body>
  <script>
    var num = parseInt(prompt("Enter a positive integer"));
    var flag = 0;

    for (i = 2; i <= num/2; i++)
    {
      if (num % i == 0)
      {
        flag = 1;
        break;
      }
    }

    if (num == 1)
      document.write(num + " is neither prime nor composite");
    else if (flag == 0)
      document.write(num + " is prime number");
    else
      document.write(num + " is not a prime number");
  </script>
</body>
</html>


No comments:

Post a Comment

SEARCH THIS BLOG