progs/factors.while
author Christian Urban <urbanc@in.tum.de>
Wed, 16 Oct 2019 11:06:32 +0100
changeset 658 a18e3c027c1f
child 659 15b69ca63b29
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
658
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// Find all factors of a given input number - J.R. Cordy August 2005
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
var n;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
write "Input n please";
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
read n;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
write "The factors of n are";
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
var f;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
f := 2;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
while n != 1 do
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
    while (n / f) * f = n do
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
        write f;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
        n := n / f;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
    end
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
    f := f + 1;
a18e3c027c1f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
end