This Blog is dedicated to Sir Johnson Lin
Learn flow chart from C language , master C with the chart!

Find prime number from 2 to 100 找出範圍內質數



D:\cppCoding\xi_code\FindPrime\FindPrime.c++
 1 //++++++++++++++++++++++++++
 2  //      FindPrime.cpp
 3  //++++++++++++++++++++++++++
 4  
 5  ///#include header
 6  #include <stdio.h>
 7  
 8  ///main_in
 9  int main ()
10  {
11      ///declare
12      int iDIV, iDVSR;
13      #define INPUTMAX 100
14      
15      ///DIV =2 ~ INPUTMAX
16      for(iDIV=2; iDIV<INPUTMAX; iDIV++)
17      {
18          ///DVSR=2 ~ DIV/DVSR
19          for(iDVSR=2; iDVSR <= (iDIV/iDVSR); iDVSR++)
20          {
21              ///remainder =zero
22              if((iDIV%iDVSR)==0) break;     // if remainder = 0, is factor, not prime then break loop
23              
24              ///+
25          }//end for
26          
27          ///Factors Existed
28          if(iDVSR > (iDIV/iDVSR))
29          {
30              ///Display Prime
31              printf("Found prime %d \n", iDIV); //iDVSR <= (iDIV/iDVSR) factor occur before loop end
32              
33              ///+
34          }//end if
35          
36          ///+
37      }//end for
38      
39      ///main_end
40      return 0;
41  } //main_end
42  

@ 下載程式碼 Download source code

+++ Link To Home Page Index 連接至目錄首頁 +++

沒有留言:

張貼留言