PHP PROGRAM TO CHECK PRIME NUMBER OR NOT - STUDENTSBLOG100 PHP TUTORIAL


Logic is same for all programs and only programming statements are different. Here we have given php programming logic to find given number is prime or not.

What is prime Number:
  • A Prime Number can be divided evenly only by 1, or itself. 
  • For example : 5 can only be divided by 1 or 5, so it is a prime number. 
  • But 6 can be divided by 1, 2, 3 and 6 so it is NOT a prime number.
Prime Number Programming Logic:
  • We should do modulo operation for the input number from 1 to input number. ie) 3 % 1 == 0 , 3 % 2 == 1 and 3 % 3 == 0. 
  • Each and every prime number will get two '0' modulo result.
  • So, each time when modulo result occurs 0, increment the count variable, ie) count++
  • After that check the condition that, if count variable == 2, input number is prime else not a prime number
Prime Number PHP program:
Output:
3 is a Prime number

Click Here to get -- > Php Tutorials by Studentsblog100

Previous
Next Post »

3 comments

Click here for comments
karthik anu
admin
7 March 2017 at 12:33 ×

Nice it seems to be good post... It will get readers engagement on the article since readres engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.
iOS Training in Chennai
Android Training in Chennai
php Training in Chennai

Reply
avatar
john stany
admin
9 June 2017 at 12:34 ×

I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
Android App Development Company

Reply
avatar
Sharon Sandy
admin
24 June 2017 at 11:46 ×

great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
web design Company
web development Company
web design Company in chennai
web development Company in chennai
web design Company in India
web development Company in India

Reply
avatar