Programozás‎ > ‎Feladatok‎ > ‎Szorzattá bontás‎ > ‎Megoldás‎ > ‎

fg_szor.dpr

Letöltés: fg_szor.dpr

{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q+,R+,S-,T-,U+,V+,W+,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

PROGRAM part;
USES SysUtils;
CONST
    maxn = 100;

VAR
    state: ARRAY [1..maxn] OF INTEGER;
    N: INTEGER;

PROCEDURE PartR(i, rem: INTEGER);
VAR
    tmp: INTEGER;
BEGIN
    IF rem = 1 THEN
    BEGIN
        Write(N,'= ');
        FOR tmp:= 1 TO i-1 DO
        BEGIN
            Write(state[tmp]);
            IF tmp < i-1 THEN Write(' * ');
        END;
        WriteLn;
    END
    ELSE
    BEGIN
        FOR tmp:= rem DOWNTO 2 DO
        BEGIN
            IF ((i = 1) OR (tmp <= state[i-1])) AND (rem MOD tmp = 0) THEN
            BEGIN
                state[i]:= tmp;
                PartR(i+1, rem DIV tmp);
            END;
        END;
    END;
END; {PartR}

BEGIN
    Write('kerek egy szamot 1 es 100 kozott: '); ReadLn(N);
    PartR(1, N);
    ReadLn;
END.
ċ
fg_szor.dpr
(1k)
Gábor Fehér,
2012. jan. 22. 4:49
Comments