Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do Factorials in VFP with Recursion
Message
 
À
22/02/2000 00:06:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00335196
Message ID:
00335788
Vues:
16
>Hi Nadya!,
>
>Let me ask you this as, perhaps, a means of expanding on this discussion a little....
>
>What 'types' of programs do you recommend using recursion? I've used them for multi-level types of organizations and relationships where they seem to do well. I'm curious as to other types of applications as well.
Lets say you had a couple of characters you needed to replace in a string, befor filing it:
eg: double quote needed to be a single quote, an ampersand needed to be an"and", do a recursion
function convertstring(lcString)
for c=1 to len(["&])
lcString=strtran(lcString,substr(["&],c,1),alltrim(substr(['bband],(c-1)*3,3))) && Where 'b' means 'blank'
endfor
return lcString

Non - recursive is faster, but eats code space.





>
>Best,
>
>DD
>
>>Doug,
>>
>>You may use recursion, if you're calculating a determinant. I created a recursion-based program in VB...
>>
>>BTW, it's a well-known fact, that each recursive program could be done in non-recursive way too.
>>
>>>>May I say that factorials are the best example for where to not use recursion?
>>>
>>>Absolutely!! I think these kinds of threads bring light to all.
>>>
>>>>Here's a much simplier, faster
>>>>and cmore compact version: <g>
>>>
>>>Show off! *bg* (he says as he harrumphs and sulks into his corner *g*)
>>>
>>>>
>>>
func Factorial
>>>lparam tnNumber
>>>   local lnResult
>>>   lnResult = 1
>>>
>>>   for lnI = 2 to tnNumber
>>>      lnResult = lnResult * lnI
>>>   endfor
>>>
>>>return lnResult
>>>
>>>Best regards,
>>>
>>>DD
Imagination is more important than knowledge
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform