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