출처 : https://github.com/YYMofROK/CodeSample/blob/master/study_sample_002.php

<?php
/////////////////////////////////////////////////////////////////////////
//
// @ 1~100 까지 소수 구하기
//
// @ 소수란...?
//
// @ 1 과 자기 자신만으로 나누어 떨어지는 자연수
//
/////////////////////////////////////////////////////////////////////////
 
 
  
for($num_1 = 1 ; $num_1 <= 100 ; $num_1 ++)
{
    $check = "ok";
  
    for($num_2 = 2 ; $num_2 < $num_1 ; $num_2 ++)
    {
        if($num_1 % $num_2 == 0)
        {
 
             $check = "no";
 
        }// end if
  
    }// end for
  
    if($check == "ok")
    {
 
        echo "[".$num_1."]은 소수 입니다<br />";
 
    }// end if
  
}// end for
  
?>

 

'!!...PHP > !!...SAMPLE' 카테고리의 다른 글

[PHP]06_버블정렬( bubble sort )  (0) 2022.04.03
[PHP]05_1~10 까지의 합  (0) 2022.04.03
[PHP]04_문자열추출  (0) 2022.04.03
[PHP]03 달력( Calendar )  (0) 2022.04.03
[PHP]01 문법예제 5X5 표에 다이아몬드 그리기  (0) 2022.04.03