Iterativa
MN = Pot(M, N) = M*M*...*M (N fattori)
1 2 3 4 5 6 7 8 9 |
Function PotIter(M, N: Integer): LongInt; Var I, Risp: LongInt; Begin Risp:=1; For I:=1 to N Do Risp:=Risp*M; PotIter:=Risp; End; |
Ricorsiva
- M0 = 1, per N = 0
- MN = M*MN-1, altrimenti
oppure
- Pot(M, N) = 1, per N = 0
- Pot(M, N) = M*Pot(M, N-1), altrimenti
1 2 3 4 5 6 7 |
Function PotRic(M, N: Integer): LongInt; Begin If(N = 0) Then PotRic:=1 Else PotRic:=M*PotRic(M, N-1); End; |