Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- This program computes the amicable numbers within the range from
- "ug" (lower limit) to "og" (upper limit), to compile run "fpc befr_zahlen.pas".
- (The method used in this program is rather simplistic.)
- Copyright (C) <March 19th, 2015> Henning POLZER, h underscore polzer at gmx dot de
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- *)
- PROGRAM befreundete_zahlen;
- VAR hilf, j, ug, og: longword; (* Standard: integer *)
- FUNCTION ts (z: longword): longword; (* Teilersumme berechnen *)
- VAR i, gegenteiler, schleife, summe: longword;
- BEGIN
- schleife := z;
- i := 2;
- summe := 1;
- REPEAT
- gegenteiler := trunc (schleife / i);
- IF schleife MOD i = 0 THEN
- IF i = gegenteiler THEN summe := summe + i (* Teiler = Gegenteiler? Nur Teiler beachten! *)
- ELSE summe := summe + gegenteiler + i;
- i := i + 1
- UNTIL gegenteiler < i;
- ts := summe
- END;
- BEGIN
- REPEAT
- writeln ('Befreundete Zahlen finden, zum Beenden fuer mind. einen Wert 0 eingeben:');
- write ('Untergrenze: '); readln (ug);
- write ('Obergrenze : '); readln (og);
- IF (ug > 0) AND (og > 0) THEN
- FOR j := ug TO og DO
- BEGIN
- hilf := ts (j);
- IF hilf <> j THEN
- IF (ts (hilf) = j) AND (hilf > j) THEN writeln (j:10, ' und ', hilf:10) (* formatierte Ausgabe *)
- END (* FOR *)
- UNTIL (ug = 0) OR (og = 0)
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement