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

因數分解流程圖 flow chart of C language for Prime Factorization pre(.) L/UL comment

C/C++ code & flow Chart !


.



D:\CPPcode\Byfactor2\Byfactor2.c++




  1 //++++++++++++++++++++++++++
  2  //      Byfactor2.cpp
  3  //++++++++++++++++++++++++++
  4  
  5  ///termino
  6  ///加入函括檔
  7  #include <stdio.h> // C
  8  //#include <iostream> // C++
  9  
 10  
 11  
 12  ///定義: 找 因數次函
 13  int IntInFactorRet(int integerin,int ifactored)
 14  {
 15      
 16      
 17      ///求因數由上次因數到平方
 18      for (int i=ifactored ; i*i<= integerin ;i++)
 19      {
 20          
 21          
 22          ///因數?
 23          if ((integerin % i)==0)
 24          {
 25              
 26              
 27              ///回傳找到因數
 28              return(i);
 29              
 30              
 31              ///FuncEnd
 32              /// +
 33          }//end if
 34          
 35          
 36          ///+
 37      }//end for
 38      
 39      
 40      ///找無因數回傳輸入值
 41      return(integerin);
 42      
 43      
 44      ///FuncEnd
 45      ///+
 46  }//end function
 47  
 48  
 49  ///主函式起點
 50  int main()
 51  {
 52      
 53      
 54      ///定義變數與常數
 55      int iFactor;
 56      int iKeyIn;
 57      int iLastInt;
 58      
 59      
 60      
 61      
 62      ///鍵盤輸入一組數字
 63      printf("key1 in number = ");
 64      scanf("%d",&iKeyIn);
 65      iLastInt=iKeyIn;
 66      
 67      
 68      
 69      ///找因數次函取最先因數
 70      iFactor=IntInFactorRet(iKeyIn,2);
 71      
 72      
 73      
 74      ///取得因數非最後整數?
 75      while(iLastInt !=iFactor)
 76      {
 77          
 78          
 79          
 80          ///最後整數約去回傳因數
 81          iLastInt=iLastInt/iFactor;
 82          
 83          
 84          
 85          /// 印因數到螢幕
 86          printf("%d*" ,iFactor);
 87          
 88          
 89          
 90          ///找因數次函取下個因數
 91          iFactor=IntInFactorRet(iLastInt,iFactor);
 92          
 93          
 94          
 95          ///+
 96      }//end while
 97      
 98      
 99      ///印最後整數到螢幕
100      printf("%d" ,iLastInt);
101      
102      
103      
104      ///主函式終點
105  } //main_end
106  
107  

.

沒有留言:

張貼留言