Home > Backend Development > PHP Problem > How to determine whether a prime number is in php

How to determine whether a prime number is in php

藏色散人
Release: 2023-03-09 13:54:01
Original
4233 people have browsed it

php method to determine whether it is a prime number: first create a PHP sample file; then use the customized "function check_ss($num) {...}" method to determine whether the specified number is a prime number.

How to determine whether a prime number is in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php determines whether it is a prime number:

The code is as follows:

<?php
    check_ss(8);
 
    function check_ss($num) {
        for($i=2; $i < $num ; $i++) {
            if($num % $i == 0) {
                echo $num. &#39;不是素数&#39;;
                exit;
            }
        }
         
        echo $num. &#39;是素数&#39;;
    }
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether a prime number is in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template