solutions/cw2/factors.while
changeset 920 7af2eea19646
parent 894 02ef5c3abc51
--- a/solutions/cw2/factors.while	Sun Sep 17 19:12:57 2023 +0100
+++ b/solutions/cw2/factors.while	Tue Sep 19 09:54:41 2023 +0100
@@ -3,12 +3,9 @@
 
 write "Input n please";
 read n;
-write "The factors of n are\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
+}