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