-
Notifications
You must be signed in to change notification settings - Fork 0
/
Greatest Common Divisor.fprg
132 lines (132 loc) · 7.83 KB
/
Greatest Common Divisor.fprg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version="1.0"?>
<flowgorithm fileversion="3.0">
<attributes>
<attribute name="name" value=""/>
<attribute name="authors" value="csfay"/>
<attribute name="about" value=""/>
<attribute name="saved" value="2022-09-19 05:17:59 PM"/>
<attribute name="created" value="Y3NmYXk7REVTS1RPUC0xVUo3SDhFOzIwMjItMDktMTk7MTI6NTE6MzkgUE07Mjg2Nw=="/>
<attribute name="edited" value="Y3NmYXk7REVTS1RPUC0xVUo3SDhFOzIwMjItMDktMTk7MDU6MTc6NTkgUE07MTk7MzAzOA=="/>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="N1, N2, Counter1, Counter2, Counter3, Watcher1, Watcher2, R1, R2, D, GCD" type="Integer" array="False" size=""/>
<declare name="Reply" type="String" array="False" size=""/>
<assign variable="Watcher1" expression="0"/>
<assign variable="Watcher2" expression="0"/>
<output expression=""Please enter two positive integers greater than zero to provide you with their GCD."" newline="True"/>
<input variable="N1"/>
<input variable="N2"/>
<if expression="N1<=0 or N2<=0">
<then>
<call expression="Main"/>
</then>
<else/>
</if>
<output expression=""You enetered the numbers: " &N1& " and "&N2" newline="True"/>
<if expression="N1==N2">
<then>
<output expression=""And as the two numbers are equal, then the Greatest Common Divisor for them is the number: " &N1& " itself."" newline="True"/>
<output expression=""Do you want to play the program again? Reply with y or n."" newline="True"/>
<input variable="Reply"/>
<if expression="Reply=="y"">
<then>
<call expression="Main"/>
</then>
<else>
<output expression=""Ok. Goodby, dear. Pleased to meet you."" newline="True"/>
</else>
</if>
</then>
<else>
<output expression=""The number " &N1&" is divisable by the following number(s):"" newline="True"/>
<for variable="Counter1" start="1" end="N1" direction="inc" step="1">
<if expression="N1%Counter1==0">
<then>
<output expression="Counter1" newline="True"/>
<assign variable="R1" expression="Counter1"/>
<assign variable="Watcher1" expression="Watcher1+1"/>
</then>
<else/>
</if>
</for>
<if expression="Watcher1 == 2">
<then>
<output expression=""Please note that the number " &N1& " is a prime number and not divisable by any other number except itself and the number 1."" newline="True"/>
</then>
<else/>
</if>
<output expression=""Ok. Now about The number " &N2& ", it is divisable by the following number(s):"" newline="True"/>
<for variable="Counter2" start="1" end="N2" direction="inc" step="1">
<if expression="N2%Counter2==0">
<then>
<output expression="Counter2" newline="True"/>
<assign variable="R2" expression="Counter2"/>
<assign variable="Watcher2" expression="Watcher2+1"/>
</then>
<else/>
</if>
</for>
<if expression="Watcher2 == 2">
<then>
<output expression=""Please note that the number " &N2& " is a prime number and not divisable by any other number except itself and the number 1."" newline="True"/>
</then>
<else/>
</if>
<if expression="Watcher1==2 and Watcher2==2">
<then>
<output expression=""Okay, as the two numbers you entered: " &N1 &" and " &N2 &" are both prime numbers and they are not equal, then there is not a Greatest Common Divisor for them. The number 1 is not considered."" newline="True"/>
<output expression=""Do you want to play the program again? Reply with y or n."" newline="True"/>
<input variable="Reply"/>
<if expression="Reply=="y"">
<then>
<call expression="Main"/>
</then>
<else>
<output expression=""Ok. Goodby, dear. Pleased to meet you."" newline="True"/>
</else>
</if>
</then>
<else>
<if expression="N1<N2">
<then>
<assign variable="D" expression="N1"/>
</then>
<else>
<assign variable="D" expression="N2"/>
</else>
</if>
<for variable="Counter3" start="1" end="D" direction="inc" step="1">
<if expression="N1%Counter3==0 && N2%Counter3==0">
<then>
<assign variable="GCD" expression="Counter3"/>
</then>
<else/>
</if>
</for>
<if expression="GCD!=1">
<then>
<output expression=""So, from the calculations above, the Greatest Common Divisor for " &N1& " and " &N2& " is: " &GCD" newline="True"/>
</then>
<else>
<output expression=""So, from the calculations above, there is no Greatest Common Divisor for the numbers " &N1& " and " &N2& ". The number 1 is not considered."" newline="True"/>
</else>
</if>
<output expression=""Do you want to play the program again? Reply with y or n."" newline="True"/>
<input variable="Reply"/>
<if expression="Reply=="y"">
<then>
<call expression="Main"/>
</then>
<else>
<output expression=""Ok. Goodby, dear. Pleased to meet you."" newline="True"/>
</else>
</if>
</else>
</if>
</else>
</if>
</body>
</function>
</flowgorithm>