progs/factors.while
author Christian Urban <urbanc@in.tum.de>
Wed, 16 Oct 2019 11:14:53 +0100
changeset 659 15b69ca63b29
parent 658 a18e3c027c1f
permissions -rw-r--r--
optional
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
}