1 //++++++++++++++++++++++++++
2 // Byfactor1.cpp
3 //++++++++++++++++++++++++++
4
5 ///termino
6 ///#include head file
7 #include <stdio.h> // C
8 //#include <iostream> // C++
9
10
11 ///Def:get factor
12 int IntInFactorRet(int integerin,int ifactored)
13 {
14
15
16 ///loop from pre-factor to sqr(in)
17 for (int i=ifactored ; i*i<= integerin ;i++)
18 {
19
20
21 /// factor?
22 if ((integerin % i)==0)
23 {
24
25
26 ///return factor
27 return(i);
28
29
30 ///FuncEnd
31 /// +
32 }//end if
33
34
35 ///+
36 }//end for
37
38
39 ///Findn't, Ret input
40 return(integerin);
41
42
43 ///FuncEnd
44 ///+
45 }//end function
46
47
48 /// main_entry
49 int main()
50 {
51
52
53 ///declare
54 int iFactor;
55 int iKeyIn;
56 int iLastInt;
57
58
59 /// Prompt & keyin
60 printf("key1 in number = ");
61 scanf("%d",&iKeyIn);
62 iLastInt=iKeyIn;
63
64
65 ///get 1st factor
66 iFactor=IntInFactorRet(iKeyIn,2);
67
68
69 ///loop if last intger unseen
70 while(iLastInt !=iFactor)
71 {
72
73
74 ///divide by factor
75 iLastInt=iLastInt/iFactor;
76
77
78 ///print factor on screen
79 printf("%d*" ,iFactor);
80
81
82 ///get next factor
83 iFactor=IntInFactorRet(iLastInt,iFactor);
84
85
86 ///+
87 }//end while
88
89
90 ///print last factor
91 printf("%d" ,iLastInt);
92
93
94 /// main_end
95 } //main_end
96
97
This Blog is dedicated to Sir Johnson Lin
flow chart of C language for Prime Factorization
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言