Categories
Games numbers PHP

Prime number in PHP

A prime number is a natural number/whole number/cardinal number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.
e.g. 2, 3, 5, 7, 11, 13, 17….etc are prime numbers; while 4, 6, 8, 9, 10, 12, 14, 15, 16….etc are composite numbers.

Program to determine if the supplied number is Prime or Composite using native bcmod() function.

<?php
$num = 26; // desired number to check
for ( $i = 2; $i <= $num - 1; $i++ ) {
    if ( bcmod( $num, $i ) == 0 ) {
        echo $num . " is composite number";
        break;
    }
}
if ( $num == $i )
    echo $num . " is prime number";
?>
'Coz sharing is caring

By Swatantra Kumar

Swatantra is an engineering leader with a successful record in building, nurturing, managing, and leading a multi-disciplinary, diverse, and distributed team of engineers and managers developing and delivering solutions. Professionally, he oversees solution design-development-delivery, cloud transition, IT strategies, technical and organizational leadership, TOM, IT governance, digital transformation, Innovation, stakeholder management, management consulting, and technology vision & strategy. When he's not working, he enjoys reading about and working with new technologies, and trying to get his friends to make the move to new web trends. He has written, co-written, and published many articles in international journals, on various domains/topics including Open Source, Networks, Low-Code, Mobile Technologies, and Business Intelligence. He made a proposal for an information management system at the University level during his graduation days.

One reply on “Prime number in PHP”

hello!,I like your writiong very a lot! proportion we krep up a corrwspondence more approximately your article on AOL?
I require ann expert onn this area to ssolve my problem.
Maybe that’s you! Looking forward to look you.

Feel free to surf to my weeb site:cheap echo of soul
gold online (Howard)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.