OPTION BASE 0 INPUT PROMPT "項数(2<=NN<=26) NN=":NN LET MAXLEVEL=6 DIM A(NN) PUBLIC NUMERIC PARA(26) FOR I=1 TO NN LET PARA(I)=I !'係数 NEXT I FOR N=2 TO MAXLEVEL CALL DISPLAYN(PARA,NN) PRINT "^";STR$(N) LET K$="" CALL COMBDISPLAYRECURSIVE(0,NN,N,A,K$) IF LEFT$(K$,1)="+" THEN LET K$=RIGHT$(K$,LEN(K$)-1) PRINT K$ NEXT N END
EXTERNAL SUB DISPLAYN(A(),N) PRINT "("; IF A(1)<0 THEN PRINT "-"; IF ABS(A(1))=1 THEN PRINT "a"; ELSEIF A(1)<>0 THEN PRINT STR$(ABS(A(1)));"a"; END IF FOR I=2 TO N IF A(I)<0 THEN PRINT "-"; ELSE PRINT "+"; IF ABS(A(I))=1 THEN PRINT MID$("abcdefghijklmnopqrstuvwxyz",I,1); ELSEIF A(I)<>0 THEN PRINT STR$(ABS(A(I)));MID$("abcdefghijklmnopqrstuvwxyz",I,1); END IF NEXT I PRINT ")"; END SUB
EXTERNAL SUB COMBDISPLAYRECURSIVE(NN,N,M,A(),K$) IF NN=N THEN LET S=M FOR J=0 TO NN LET S=S-A(J) NEXT J IF S=0 THEN LET V=FAC(M) FOR J=0 TO N-1 LET V=V*PARA(J+1)^A(J)/FAC(A(J)) !'多項定理 NEXT J IF V<0 THEN LET L$="-" ELSE LET L$="+" END IF IF V<>0 THEN IF ABS(V)<>1 THEN LET L$=L$ & STR$(ABS(V)) FOR J=0 TO N-1 IF A(J)=1 THEN LET L$=L$ & MID$("abcdefghijklmnopqrstuvwxyz",J+1,1) ELSEIF A(J)>1 THEN LET L$=L$ & MID$("abcdefghijklmnopqrstuvwxyz",J+1,1) & "^" & STR$(A(J)) END IF NEXT J LET K$=L$ & K$ END IF END IF EXIT SUB END IF FOR I=0 TO M LET A(NN)=I CALL COMBDISPLAYRECURSIVE(NN+1,N,M,A,K$) NEXT I END SUB
EXTERNAL FUNCTION FAC(X) LET S=1 FOR I=2 TO X LET S=S*I NEXT I LET FAC=S END FUNCTION
|