progs/while-tests/factors.while
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 06 Oct 2020 00:39:34 +0100
changeset 775 16aafc7691d8
parent 742 b5b5583a3a08
child 824 284ac979f289
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
659
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
     1
// Find all factors of a given input number
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
     2
// by J.R. Cordy August 2005
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
     3
658
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
write "Input n please";
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
read n;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
write "The factors of n are";
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
f := 2;
659
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
     8
while n != 1 do {
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
     9
    while (n / f) * f == n do {
658
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
        write f;
659
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
    11
        n := n / f
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
    12
    };
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
    13
    f := f + 1
15b69ca63b29 optional
Christian Urban <urbanc@in.tum.de>
parents: 658
diff changeset
    14
}