solutions/cw3/factors.while
changeset 905 15973df32613
parent 894 02ef5c3abc51
--- a/solutions/cw3/factors.while	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw3/factors.while	Wed Dec 21 14:33:05 2022 +0000
@@ -5,10 +5,7 @@
 read n;
 write "The factors of n are:\n";
 f := 2;
-while n != 1 do {
-    while (n / f) * f == n do {
-        write f; write "\n";
-        n := n / f
-    };
-    f := f + 1
-}
\ No newline at end of file
+while (f < n / 2 + 1) do {
+  if ((n / f) * f == n) then  { write(f); write "\n" } else { skip };
+  f := f + 1
+}