updated while tests
authorChristian Urban <christian.urban@kcl.ac.uk>
Fri, 26 Feb 2021 08:47:18 +0000
changeset 824 284ac979f289
parent 823 bde572a54112
child 825 dca072e2bb7d
updated while tests
progs/while-tests/and.while
progs/while-tests/andor.while
progs/while-tests/factors.while
progs/while-tests/or.while
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/while-tests/and.while	Fri Feb 26 08:47:18 2021 +0000
@@ -0,0 +1,6 @@
+n := 0;
+if (n == 0) && (n == 1) then {
+    write "yes"
+} else {
+    write "no"
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/while-tests/andor.while	Fri Feb 26 08:47:18 2021 +0000
@@ -0,0 +1,6 @@
+n := 0;
+if ((n == 0) || (n == 1)) && ((n == 2) || (n <= 0)) then {
+    write "yes"
+} else {
+    write "no"
+}
\ No newline at end of file
--- a/progs/while-tests/factors.while	Thu Feb 04 10:19:48 2021 +0000
+++ b/progs/while-tests/factors.while	Fri Feb 26 08:47:18 2021 +0000
@@ -1,14 +1,11 @@
 // Find all factors of a given input number
-// by J.R. Cordy August 2005
+
 
 write "Input n please";
 read n;
 write "The factors of n are";
 f := 2;
-while n != 1 do {
-    while (n / f) * f == n do {
-        write f;
-        n := n / f
-    };
-    f := f + 1
+while (f < n / 2 + 1) do {
+  if ((n / f) * f == n) then  { write(f) } else { skip };
+  f := f + 1
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/while-tests/or.while	Fri Feb 26 08:47:18 2021 +0000
@@ -0,0 +1,6 @@
+n := 0;
+if (n == 0) || (n == 1) then {
+    write "yes"
+} else {
+    write "no"
+}
\ No newline at end of file